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

Fix Common Errors on Demo/Configs #125

Open
wants to merge 5 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
20 changes: 12 additions & 8 deletions configs/attribute_predict_coarse/global_predictor_resnet_attr.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@
inter_channels=[2048, 4096],
outchannels=4096),
attr_predictor=dict(
type='AttrPredictor', inchannels=4096, outchannels=attribute_num),
loss_attr=dict(
type='BCEWithLogitsLoss',
ratio=1,
weight=None,
size_average=None,
reduce=None,
reduction='mean'),
type='AttrPredictor',
inchannels=4096,
outchannels=attribute_num,
loss_attr=dict(
type='BCEWithLogitsLoss',
ratio=1,
weight=None,
size_average=None,
reduce=None,
reduction='mean',
),
),
pretrained='checkpoint/resnet50.pth')

pooling = 'Global'
Expand Down
20 changes: 12 additions & 8 deletions configs/attribute_predict_coarse/global_predictor_vgg_attr.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@
inter_channels=[512, 4096],
outchannels=4096),
attr_predictor=dict(
type='AttrPredictor', inchannels=4096, outchannels=attribute_num),
loss_attr=dict(
type='BCEWithLogitsLoss',
ratio=1,
weight=None,
size_average=None,
reduce=None,
reduction='mean'),
type='AttrPredictor',
inchannels=4096,
outchannels=attribute_num,
loss_attr=dict(
type='BCEWithLogitsLoss',
ratio=1,
weight=None,
size_average=None,
reduce=None,
reduction='mean',
),
),
pretrained='checkpoint/vgg16.pth')

pooling = 'Global'
Expand Down
2 changes: 1 addition & 1 deletion configs/landmark_detect/landmark_detect_resnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

model = dict(
type='LandmarkDetector',
backbone=dict(type='ResNet', layer_setting='resnet50'),
backbone=dict(type='ResNet', setting='resnet50'),
global_pool=dict(
type='GlobalPooling',
inplanes=(7, 7),
Expand Down
3 changes: 2 additions & 1 deletion demo/test_attr_predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def main():
img_tensor = get_img_tensor(args.input, args.use_cuda)
# global attribute predictor will not use landmarks
# just set a default value
landmark_tensor = torch.zeros(8)
# TODO: Add landmark demo support
landmark_tensor = torch.zeros(16).view(1, -1)
cfg.model.pretrained = None
model = build_predictor(cfg.model)
load_checkpoint(model, args.checkpoint, map_location='cpu')
Expand Down
3 changes: 2 additions & 1 deletion demo/test_cate_attr_predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def main():
img_tensor = get_img_tensor(args.input, args.use_cuda)
# global attribute predictor will not use landmarks
# just set a default value
landmark_tensor = torch.zeros(8)
# TODO: Add landmark demo support
landmark_tensor = torch.zeros(16).view(1, -1)

model = build_predictor(cfg.model)
load_checkpoint(model, args.checkpoint, map_location='cpu')
Expand Down
2 changes: 1 addition & 1 deletion demo/test_landmark_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def main():

args = parse_args()
cfg = Config.fromfile(args.config)

cfg.model.pretrained = None
img_tensor, w, h = get_img_tensor(args.input, args.use_cuda, get_size=True)

# build model and load checkpoint
Expand Down
10 changes: 6 additions & 4 deletions mmfashion/utils/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ def get_img_tensor(img_path, use_cuda, get_size=False):

img_size = (224, 224) # crop image to (224, 224)
img.thumbnail(img_size, Image.ANTIALIAS)
w, h = img.size
img = img.convert('RGB')
normalize = transforms.Normalize(
mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
transform = transforms.Compose([
transforms.RandomResizedCrop(img_size[0]),
transforms.RandomHorizontalFlip(),
transforms.Pad((max(h - w, 0)//2,
max(w - h, 0)//2), padding_mode='edge'),
transforms.ToTensor(),
normalize,
])
Expand Down Expand Up @@ -62,8 +63,9 @@ def show_img(img_tensor):
def draw_landmarks(img_file, landmarks, r=2):
img = Image.open(img_file)
draw = ImageDraw.Draw(img)
w, h = img.size
for i, lm in enumerate(landmarks):
x = lm[0]
y = lm[1]
x = lm[0] * (w / 224.)
y = lm[1] * (h / 224.)
draw.ellipse([(x - r, y - r), (x + r, y + r)], fill=(255, 0, 0, 0))
img.show()