From 57c6e9e7e32df8c2bfc1b096f62f7566fe3bcf83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Do=C4=9Fa=C3=A7=20Eldenk?= Date: Tue, 2 Feb 2021 16:43:17 +0300 Subject: [PATCH 1/5] Fix config loss_attr runtime problem --- .../global_predictor_resnet_attr.py | 20 +++++++++++-------- .../global_predictor_vgg_attr.py | 20 +++++++++++-------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/configs/attribute_predict_coarse/global_predictor_resnet_attr.py b/configs/attribute_predict_coarse/global_predictor_resnet_attr.py index 0cd68108c..6e9d79263 100644 --- a/configs/attribute_predict_coarse/global_predictor_resnet_attr.py +++ b/configs/attribute_predict_coarse/global_predictor_resnet_attr.py @@ -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' diff --git a/configs/attribute_predict_coarse/global_predictor_vgg_attr.py b/configs/attribute_predict_coarse/global_predictor_vgg_attr.py index 46db612a0..5f492a974 100644 --- a/configs/attribute_predict_coarse/global_predictor_vgg_attr.py +++ b/configs/attribute_predict_coarse/global_predictor_vgg_attr.py @@ -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' From cd587cefd1818be2ac12254ec9083c2f9e3f0e65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Do=C4=9Fa=C3=A7=20Eldenk?= Date: Tue, 2 Feb 2021 16:45:34 +0300 Subject: [PATCH 2/5] Fix image malformation and landmark drawings --- mmfashion/utils/image.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/mmfashion/utils/image.py b/mmfashion/utils/image.py index 26f287065..70dbf8823 100644 --- a/mmfashion/utils/image.py +++ b/mmfashion/utils/image.py @@ -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, ]) @@ -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() From 3b3931180d0683a05f95304fc6182a4c0e70710e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Do=C4=9Fa=C3=A7=20Eldenk?= Date: Tue, 2 Feb 2021 16:47:56 +0300 Subject: [PATCH 3/5] Fix landmark format --- demo/test_attr_predictor.py | 3 ++- demo/test_cate_attr_predictor.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/demo/test_attr_predictor.py b/demo/test_attr_predictor.py index 2fc3f9566..49fb5da5b 100644 --- a/demo/test_attr_predictor.py +++ b/demo/test_attr_predictor.py @@ -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') diff --git a/demo/test_cate_attr_predictor.py b/demo/test_cate_attr_predictor.py index 54e057700..2da1e79e1 100644 --- a/demo/test_cate_attr_predictor.py +++ b/demo/test_cate_attr_predictor.py @@ -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') From 63b9915b006796cc7cad28e84cb5cb1a0e86f384 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Do=C4=9Fa=C3=A7=20Eldenk?= Date: Tue, 2 Feb 2021 16:50:09 +0300 Subject: [PATCH 4/5] Fix layer_setting to setting for landmark detect --- configs/landmark_detect/landmark_detect_resnet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configs/landmark_detect/landmark_detect_resnet.py b/configs/landmark_detect/landmark_detect_resnet.py index 4d7af0796..b3ffa2a95 100644 --- a/configs/landmark_detect/landmark_detect_resnet.py +++ b/configs/landmark_detect/landmark_detect_resnet.py @@ -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), From c8ad28078b774a5cb539939e375a155e1dd689f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Do=C4=9Fa=C3=A7=20Eldenk?= Date: Tue, 2 Feb 2021 16:51:54 +0300 Subject: [PATCH 5/5] Fix pretrained model in landmark --- demo/test_landmark_detector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demo/test_landmark_detector.py b/demo/test_landmark_detector.py index fffde6511..e467527d5 100644 --- a/demo/test_landmark_detector.py +++ b/demo/test_landmark_detector.py @@ -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