update image extraction script
@@ -8,44 +8,39 @@ image features.
For example, to extract the image feature of COCO images:
`python examples/extract_image_feature.py -t vqa_v1 -im resnet152`.
-The CNN model and layer is specified at `--image-cnntype` and `--image-layernum`
-in `parlai.core.image_featurizers`.
-
For more options, check `parlai.core.image_featurizers`
"""
from parlai.core.params import ParlaiParser
from parlai.agents.repeat_label.repeat_label import RepeatLabelAgent
from parlai.core.worlds import create_task
-from parlai.core.image_featurizers import ImageLoader
+from parlai.core.utils import ProgressLogger
-import random
def main():
- random.seed(42)
-
# Get command line arguments
- parser = ParlaiParser()
- parser.add_argument('-n', '--num-examples', default=10)
+ parser = ParlaiParser(True, False)
parser.set_defaults(datatype='train:ordered')
- ImageLoader.add_cmdline_args(parser)
opt = parser.parse_args()
-
+ bsz = opt.get('batchsize', 1)
opt['no_cuda'] = False
opt['gpu'] = 0
+ opt['num_epochs'] = 1
# create repeat label agent and assign it to the specified task
agent = RepeatLabelAgent(opt)
world = create_task(opt, agent)
- # Show some example dialogs.
- with world:
- for k in range(int(opt['num_examples'])):
+ logger = ProgressLogger(should_humanize=False)
+ print("Beginning image extraction...")
+ exs_seen = 0
+ total_exs = world.num_examples()
+ while not world.epoch_done():
world.parley()
- print(world.display() + '\n~~')
- if world.epoch_done():
- print('EPOCH DONE')
- break
+ exs_seen += bsz
+ logger.log(exs_seen, total_exs)
+ print("Finished extracting images")
+
if __name__ == '__main__':
main()
