【问题标题】:How does the tf.train.batch_join() function in tensorflow work?tensorflow 中的 tf.train.batch_join() 函数是如何工作的?
【发布时间】:2018-01-04 23:13:45
【问题描述】:

我正在尝试在 tensorflow 中训练神经网络。我使用 tf.train.batch_join() 函数加载数据及其标签。我做这样的事情:

image_batch, label_batch, image_batch_f = tf.train.batch_join(
        images_and_labels, batch_size=batch_size_placeholder,
        #shapes=[(args.image_size, args.image_size, 3), ()], enqueue_many=True,
        shapes=[(args.image_height, args.image_width, 3), (), (args.image_height, args.image_width, 3)], enqueue_many=True,
        capacity=4 * nrof_preprocess_threads * args.batch_size,
        allow_smaller_final_batch=True)
    image_batch = tf.identity(image_batch, 'image_batch')
    image_batch = tf.identity(image_batch, 'input')
    label_batch = tf.identity(label_batch, 'label_batch')
    image_batch_f = tf.identity(image_batch_f, 'flipped_images_batch')

在这里,我得到三批数据。一批图像、一批标签和一批与该批图像中相同的图像的翻转图像。我想在这批图像和翻转图像上提取特征。下面的行通过网络传递批量数据。

    # Build the inference graph
    prelogits, _ = network.inference(image_batch, args.keep_probability,
        phase_train=phase_train_placeholder, feature_dimension=args.embedding_size,
        weight_decay=args.weight_decay)


    features = tf.nn.l2_normalize(prelogits, 1, 1e-10, name='embeddings')

    #getting the flipped embeddings
    prelogits_f, _ = network.inference(image_batch_f,args.keep_probability,
                    phase_train=phase_train_placeholder,feature_dimension=args.embedding_size,
                    weight_decay=args.weight_decay,reuse=True)
    features_flipped_images = tf.nn.l2_normalize(prelogits_f,1,1e-10,name='embeddings_f')

为了获得这两个功能,我在 features 和 features_flipped_images 操作上运行了 session.run()。像这样的:

feed_dict = {phase_train_placeholder:False, batch_size_placeholder:batch_size}
emb, emb_f = sess.run([features, features_flipped_images],feed_dict=feed_dict)

我的问题如下。我猜当我在功能上运行会话时,即 batch_join 函数将分派一批大小为 batch_size 的图像。但是当我对 features_flipped_images 执行 session.run() 时,该函数还将从 batch_join 函数中获取一批翻转的图像。执行 features_flipped_images 时,batch_join 函数是否会分派一批新的翻转图像?还是执行特征时生成的同一批翻转图像?如果没有,那么我该怎么做?我想在这批图像和一批翻转图像上提取特征。

【问题讨论】:

    标签: tensorflow deep-learning


    【解决方案1】:

    我的猜测是每次运行 [features, features_flipped_images] 只会得到同一批数据。举个例子:

    imgs_batch,labels_batch = tf.train.batch([img, label]...)
    

    那么,如果您想查看批次中的内容:

    imgs_data, labels_data = sess.run([imgs_batch, labels_batch])
    

    你看,当你运行 sess.run([features, features_flipped_images],..) 时它是相似的。我不认为你会得到两批,否则imgs_data和labels_data是不对应的。

    【讨论】:

    • 我不确定它是否是同一批次,因为如果我将图像和翻转图像的特征连接起来并使用连接特征进行匹配,我的系统的性能会显着下降,而实际上应该改进匹配的性能。我仍然不清楚批处理加载器。
    猜你喜欢
    • 2020-05-04
    • 1970-01-01
    • 2017-09-10
    • 2017-12-21
    • 2020-02-17
    • 2020-01-15
    • 2018-04-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多