Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue#3 #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions model/embedding.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
import torch.nn as nn
import torch.nn.functional as F
from model.resnet import resnet18
from model.resnet import resnet34
from model.resnet import resnet50
from model.resnet import resnet101
from model.resnet import resnet152
from config.base_config import cfg


class EmbeddingResnet(nn.Module):
def __init__(self):
def __init__(self,model_name = 'resnet50'):
super(EmbeddingResnet, self).__init__()
if model_name == 'resnet18':
resnet = resnet18(pretrained=True)
elif model_name == 'resnet34':
resnet = resnet34(pretrained=True)
elif model_name == 'resnet50':
resnet = resnet50(pretrained=True)
elif model_name == 'resnet101':
resnet = resnet101(pretrained=True)
elif model_name == 'resnet152':
resnet = resnet152(pretrained=True)
else:
raise ValueError('The model doesnt exist! Please choose from resnet18,resnet34,resnet50,resnet101,resnet152.')

resnet = resnet50(pretrained=True)
self.features = nn.Sequential(resnet.conv1, resnet.bn1, resnet.relu, resnet.maxpool, resnet.layer1,
resnet.layer2, resnet.layer3, resnet.layer4, resnet.avgpool)
# Fix blocks
Expand Down
2 changes: 1 addition & 1 deletion model/net.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def get_model(args, device):
# Model
embeddingNet = None
if (args.dataset == 'custom') or (args.dataset == 'vggface2'):
embeddingNet = embedding.EmbeddingResnet()
embeddingNet = embedding.EmbeddingResnet(args.arch)
elif (args.dataset == 'mnist') or (args.dataset == 'fmnist'):
embeddingNet = embedding.EmbeddingLeNet()
else:
Expand Down
2 changes: 2 additions & 0 deletions train.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ def save_checkpoint(state, file_name):

parser.add_argument('--train_log_step', type=int, default=100, metavar='M',
help='Number of iterations after which to log the loss')
parser.add_argument('--arch', type = str, default ='resnet50',
help="model architecture . default resnet50 . Choose from 'resnet18', 'resnet34', 'resnet50', 'resnet101','resnet152'")

global args, device
args = parser.parse_args()
Expand Down