【问题标题】:Tf-slim: ValueError: Variable vgg_19/conv1/conv1_1/weights already exists, disallowed. Did you mean to set reuse=True in VarScope?Tf-slim: ValueError: 变量 vgg_19/conv1/conv1_1/weights 已经存在,不允许。您的意思是在 VarScope 中设置 reuse=True 吗?
【发布时间】:2018-01-15 13:43:55
【问题描述】:

我正在使用 tf-slim 从几批图像中提取特征。问题是我的代码适用于第一批,之后我得到标题中的错误。我的代码是这样的:

for i in range(0, num_batches):
    #Obtain the starting and ending images number for each batch
    batch_start = i*training_batch_size
    batch_end = min((i+1)*training_batch_size, read_images_number)
    #obtain the images from the batch
    images = preprocessed_images[batch_start: batch_end]
    with slim.arg_scope(vgg.vgg_arg_scope()) as sc:
        _, end_points = vgg.vgg_19(tf.to_float(images), num_classes=1000, is_training=False)
        init_fn = slim.assign_from_checkpoint_fn(os.path.join(checkpoints_dir,  'vgg_19.ckpt'),slim.get_model_variables('vgg_19'))
        feature_conv_2_2 = end_points['vgg_19/pool5']

如您所见,在每批中,我选择了一批图像并使用 vgg-19 模型从 pool5 层中提取特征。但是在第一次迭代之后,我在尝试获取端点的行中出现错误。正如我在互联网上发现的一种解决方案是每次都重置图表,但我不想这样做,因为在我使用这些提取的特征训练的代码的后面部分中,我的图表中有一些权重。我不想重置它们。任何线索高度赞赏。谢谢!

【问题讨论】:

    标签: tensorflow deep-learning tensorflow-gpu tf-slim


    【解决方案1】:

    您应该创建一次图表,而不是循环。错误消息准确地告诉您 - 您尝试构建相同的图表两次。

    所以它应该是(在伪代码中)

    create_graph()
    load_checkpoint()
    
    for each batch:
      process_data()
    

    【讨论】:

    • 所以基本上使用占位符作为我的 vgg.vgg_19 对象的输入,并在运行时将图像传递给占位符吗?
    猜你喜欢
    • 1970-01-01
    • 2018-05-22
    • 2018-10-17
    • 1970-01-01
    • 2019-03-05
    • 1970-01-01
    • 2018-02-07
    • 1970-01-01
    • 2018-03-19
    相关资源
    最近更新 更多