channel=channel_mean)

    dataset_args["dataset_cls"] = ReferitDataset
    dataset_args["expand_objects"] = (args.mode == "crop_all")
    dataset_args["crop_builder"] = crop_builder

else:
    assert False, "Invalid mode: {}".format(args.mode)


# create network
print("Create network...")
ft_output = resnet.create_resnet(images,
                                 resnet_out=args.feature_name,
                                 resnet_version=args.resnet_version,
                                 is_training=False)

extract_features(
    img_input=images,
    ft_output=ft_output,
    dataset_cstor=dataset_cstor,
    dataset_args=dataset_args,
    batchifier_cstor=ReferitBatchifier,
    out_dir=args.out_dir,
    set_type=["all"],
    network_ckpt=args.ckpt,
    batch_size=args.batch_size,
    no_threads=args.no_thread,
    gpu_ratio=args.gpu_ratio)

Пример #2
0
print("Create networks...")
if args.network == "resnet":
    ft_output = resnet.create_resnet(images,
                                     resnet_out=args.feature_name,
                                     resnet_version=args.resnet_version,
                                     is_training=False)
    # create network
    with slim.arg_scope(slim_utils.resnet_arg_scope(is_training=False)):
        _, end_points = resnet_v1.resnet_v1_152(images, 1000)  # 1000 is the number of softmax class


elif args.network == "vgg":
    _, end_points = vgg.vgg_16(images, is_training=False, dropout_keep_prob=1.0)
    ft_name = os.path.join("vgg_16", args.feature_name)
    ft_output = end_points[ft_name]
else:
    assert False, "Incorrect Network"


extract_features(
    img_input = images,
    ft_output = ft_output,
    dataset_cstor = dataset_cstor,
    dataset_args = {"folder": args.data_dir, "image_builder":image_builder, "crop_builder":crop_builder, "dataset_name": args.dataset_name},
    batchifier_cstor = OracleBatchifier,
    out_dir = args.out_dir,
    set_type = args.set_type,
    network_ckpt=args.ckpt,
    batch_size = args.batch_size,
    no_threads = args.no_thread,
    gpu_ratio = args.gpu_ratio)
source = 'image'
images = tf.placeholder(tf.float32, [None, args.img_size, args.img_size, 3],
                        name=source)
image_builder = RawImageBuilder(args.img_dir,
                                height=args.img_size,
                                width=args.img_size,
                                channel=channel_mean)

# create network
print("Create network...")
ft_output = resnet.create_resnet(images,
                                 resnet_out=args.feature_name,
                                 resnet_version=args.resnet_version,
                                 is_training=False)

extract_features(img_input=images,
                 ft_output=ft_output,
                 dataset_cstor=VQADataset,
                 dataset_args={
                     "folder": args.data_dir,
                     "year": args.year,
                     "image_builder": image_builder
                 },
                 batchifier_cstor=VQABatchifier,
                 out_dir=args.out_dir,
                 set_type=args.set_type,
                 network_ckpt=args.ckpt,
                 batch_size=args.batch_size,
                 no_threads=args.no_thread,
                 gpu_ratio=args.gpu_ratio)