help="1=Yes|0=No", choices=[1, 0]) parser.add_argument("--image_path", type=str, help="Path to the Image for Generation of Captions") parser.add_argument("--validation_data", type=str, help="Path to the Validation Data for evaluation") args = parser.parse_args() config = Configuration(vars(args)) if config.mode == "train": caption_file = 'Data/training.txt' feature_file = 'Data/training_features.npy' vocab, wtoidx, training_data = generate_captions(config.word_threshold, config.max_len, caption_file, feature_file) features, captions = training_data[:, 0], training_data[:, 1] features = np.array([feat.astype(float) for feat in features]) data = (vocab.tolist(), wtoidx.tolist(), features, captions) model = Caption_Generator(config, data=data) loss, inp_dict = model.build_train_graph() model.train(loss, inp_dict) elif config.mode == "test": if os.path.exists(args.image_path): model = Caption_Generator(config) model.decode(args.image_path) else: print "Please provide a valid image path.\n Usage:\n python main.py --mode test --image_path VALID_PATH"
help="If mode is test then, Path to the Image for Generation of Captions") parser.add_argument( "--load_image", help= "If mode is test then, displays and stores image with generated caption", action="store_true") parser.add_argument( "--validation_data", type=str, help="If mode is eval then, Path to the Validation Data for evaluation") args = parser.parse_args() config = Configuration(vars(args)) if config.mode == "train": vocab, wtoidx, training_data = generate_captions( config.word_threshold, config.max_len, args.coco_caption_path, args.flickr_caption_path, args.feature_path, config.data_is_coco) features, captions = training_data[:, 0], training_data[:, 1] features = np.array([feat.astype(float) for feat in features]) data = (vocab.tolist(), wtoidx.tolist(), features, captions) model = Caption_Generator(config, data=data) loss, inp_dict = model.build_train_graph() model.train(loss, inp_dict) elif config.mode == "test": if os.path.exists(args.image_path): model = Caption_Generator(config) model.decode(args.image_path) else: print "Please provide a valid image path.\n Usage:\n python main.py --mode test --image_path VALID_PATH"