简体   繁体   English

如何在TensorFlow中使用我自己的图像?

[英]How do i use my own images in TensorFlow?

I know this question has been asked before but I haven't been able to find an answer I can work with yet. 我知道之前已经问过这个问题,但我还没找到能够合作的答案。 I'm new to Python and Tensorflow but managed to get my accuracy up to +-99.3% with the MNIST-image set. 我是Python和Tensorflow的新手,但设法使用MNIST图像集将我的准确度提高到+ -99.3%。 Now I would like to try to use my own images but this proved to be more difficult to me than expected. 现在我想尝试使用我自己的图像,但事实证明这比我预期的要困难。

I have read the tutorial page on the Tensorflow site hundreds of times but it just doesn't make sense to me and whatever I try I just end up with warnings. 我已经在Tensorflow网站上阅读了数百次的教程页面,但这对我来说没有意义,无论我尝试什么,我最终都会收到警告。 Now I want to figure it out myself but does anyone have an idea which way would be the easiest to work with my own images? 现在我想弄清楚自己,但有没有人知道哪种方式最容易使用我自己的图像? Or any examples? 或者任何例子? I've been looking online for them but it feels like I'm finding 1000's of them but none of them gets explained in a way I can understand. 我一直在网上找他们,但感觉我找到了1000个,但没有一个以我能理解的方式得到解释。

Thanks for your help in advance. 感谢您的帮助。

OK, so putting this together, you have 42 classes, and expect to have approximately 10 pictures each. 好吧,所以把它放在一起,你有42个课程,并期望每个大约有10个图片。

This places you pretty squarely in the need of two things: 这让你非常需要两件事:

You've already addressed the likely need for data augmentation in the comments, and you're spot on: In order to make the most of your 10 images per class, you'll want to apply a whole bunch of transformations to them. 您已经在评论中解决了数据扩充的可能需求,您可以发现:为了充分利用每个类的10个图像,您需要对它们应用一大堆变换。 Probably many more than 10/20 total images: 可能超过10/20的总图像:

  • Cropping 裁剪
  • Scaling 缩放
  • Noise 噪声
  • Contrast/color/brightness adjustment 对比度/颜色/亮度调整
  • Rotation 回转

A good example of data augmentation for image classification is in the official resnet example model 图像分类的数据增强的一个很好的例子是官方的resnet示例模型

The second is transfer learning. 第二是转学习。 When you're trying to learn a model on 42 classes from quite little data, you'll probably be able to do better by starting from a model trained on other data, and then retraining the last (few) layers with your new dataset. 当您尝试从非常少的数据中学习42个类的模型时,您可能可以通过从其他数据训练的模型开始,然后使用新数据集重新训练最后(几个)层来做得更好。 The reasoning behind this is that the much larger example space of the initial training will help your classifier learn a variety of common image features, which your transfer-learned classifier can use to achieve higher-level recognition more quickly. 这背后的原因是初始训练的更大的示例空间将帮助您的分类器学习各种常见的图像特征,您的转移学习分类器可以使用它来更快地实现更高级别的识别。

An alternative, of course, is you could do some form of active learning -- train a classifier, and then show it images of your tokens (perhaps via webcam, classifying each frame), and when it gets one wrong, save that as an example for the next training round. 当然,另一种选择是,您可以进行某种形式的主动学习 - 训练分类器,然后显示您的令牌图像(可能通过网络摄像头,对每个帧进行分类),当它出错时,将其保存为下一轮训练的例子。 This takes more work and you'd have to build some infrastructure for it, so I'd start with transfer learning. 这需要更多的工作,你必须为它构建一些基础设施,所以我开始转移学习。

You then have the question of what architecture to start with for the transfer learning. 然后,您将了解为转移学习开始的架构问题。 Inception is probably too much for what you're doing, but the stock MNIST model is probably more simple than you want. 对于你正在做的事情,起初可能太多了,但是股票MNIST模型可能比你想要的更简单。 You'll need to do some experimentation -- a modified LeNet-style classifier like the common MNIST examples can work pretty well (add another convolutional layer, add batchnorm and maybe a bit of dropout). 你需要做一些实验 - 一个改进的LeNet风格的分类器,比如常见的MNIST例子可以很好地工作(添加另一个卷积层,添加batchnorm,也许有点辍学)。 Alternatively, you could start with a pretrained Mobilenet network and transfer learn from it. 或者,您可以从预先训练的Mobilenet网络开始,并从中学习转移。 I'd be tempted to start with the latter, unless you've got some strict computational limits to inference speed. 我很想从后者开始,除非你对推理速度有一些严格的计算限制。

For your images, I'd start by creating a directory of JPEG images. 对于你的图像,我首先要创建一个JPEG图像目录。 The most "official" way to handle them would be the process in this answer . 处理它们的最“官方”方式是这个答案中的过程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM