fix for extracting resnet features from zipfile
@@ -182,15 +182,19 @@ class ImageLoader():
def load(self, path):
opt = self.opt
mode = opt.get('image_mode', 'raw')
+ is_zip = False
if mode is None or mode == 'none':
# don't need to load images
return None
elif '.zip' in path:
# assume format path/to/file.zip/image_name.jpg
+ is_zip = True
sep = path.index('.zip')+4
zipname = path[:sep]
file_name = path[sep+1:]
path = ZipFile(zipname, 'r').open(file_name)
+ prepath = os.path.join(opt['datapath'], opt['task'])
+ imagefn = ''.join(zipname.strip('.zip').split('/')[-2:]) + path.name
if mode == 'raw':
# raw just returns RGB values
return Image.open(path).convert('RGB')
@@ -199,6 +203,7 @@ class ImageLoader():
return self.img_to_ascii(path)
else:
# otherwise, looks for preprocessed version under 'mode' directory
+ if not is_zip:
prepath, imagefn = os.path.split(path)
dpath = os.path.join(prepath, mode)
