Tensorflow中的Triplet,Siamese和Softmax [英] Triplet, Siamese and Softmax in Tensorflow

查看:304
本文介绍了Tensorflow中的Triplet,Siamese和Softmax的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想针对两种不同的大图像数据集比较以下CNN的性能.目的是测量两个图像之间的相似性,而这两个图像在训练过程中均未见过.我可以使用2个GPU和16个CPU内核.

I'd like to compare the performance of following types of CNNs for two different large image data sets. The goal is to measure the similarity between two images, which both have not been seen during training. I have access to 2 GPUs and 16 CPU cores.

  1. 三重CNN(输入:三张图片,标签:在位置编码)
  2. 暹罗CNN(输入:两张图片,标签:一个二进制标签)
  3. 用于功能学习的Softmax CNN(输入:一张图像,标签:一个整数标签)

对于Softmax,我可以将数据存储为二进制格式(顺序存储标签和图像).然后使用TensorFlow阅读器阅读它.

For Softmax I can store the data in a binary format (Sequentially store label and image). Then read it with a TensorFlow reader.

要对Triplet和Siamese Networks使用相同的方法,我必须提前生成组合并将其存储到磁盘.这将导致创建文件所需的时间和磁盘空间上的大量开销.怎么能即时完成?

To use the same method for Triplet and Siamese Networks, I'd have to generate the combinations in advance and store them to disk. That would result in a big overhead in both the time it takes to create the file and in disk space. How can it be done on the fly?

另一种简单的方法是使用feed_dict,但这会很慢.因此,如果可以并行运行与feed_dict相同的函数并将结果转换为TensorFlow张量,则可以解决该问题.但是据我所知,这种转换并不存在,因此首先必须使用TensorFlow阅读器读取文件,然后使用TensorFlow方法完成整个过程.这是正确的吗?

Another easy way would be to use feed_dict, but this would be slow. Therefore the problem would be solved if it would be possible to run the same function which I'd use for feed_dict in parallel and convert the result to a TensorFlow tensor as a last step. But as far as I know such a conversion does not exist so one has to read the files with a TensorFlow reader in the first place and do the whole process with TensorFlow methods. Is this correct?

推荐答案

简短的答案是使用numpy在线创建线对/三胞胎,无需将其转换为张量,因为feed_dict参数已经接受了numpy数组.

Short answer do the pair/triplet creation online with numpy no need to convert it to a tensor as the feed_dict arguments accepts numpy arrays already.

最好是将现有批次中的tf.nn.embedding_lookup()itertools结合使用来创建对的索引,但是对于幼稚的非最佳解决方案,您可以查看我的github存储库.我在哪里重新实现了暹罗咖啡的例子. 显然,它的效率不如使用张量流队列,但我的建议是在使用纯张量流解决方案之前先尝试使用此基准.

The best would be to use tf.nn.embedding_lookup() from already existing batches in combination with itertools to create the indices of the pairs but for a naïve non-optimal solution you can look at the gen_batches_siamese.py script in my github repository. Where I reimplemented the caffe siamese example. Obviously it will be less efficient than using tensorflow queues but my advice would be to try this baseline first before going to the pure tensorflow solution.

这篇关于Tensorflow中的Triplet,Siamese和Softmax的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆