简体   繁体   English

在 Tensorflow 上调整 MNIST 数据的大小

[英]Resize MNIST Data on Tensorflow

I have been working on MNIST dataset to learn how to use Tensorflow and Python for my deep learning course.我一直在研究 MNIST 数据集,以学习如何在我的深度学习课程中使用 Tensorflow 和 Python。

I could read the data internally/externally and also train it in softmax and cnn thanks to tensorflow tutorial at website.由于网站上的 tensorflow 教程,我可以在内部/外部读取数据,还可以在 softmax 和 cnn 中对其进行训练。 At the end, I could get >%90 in softmax, >%98 in cnn, accuracy.最后,我可以在 softmax 中获得 >%90,在 cnn 中获得 >%98,准确度。

My problem is that I want to resize all images on MNIST as 14x14 and train it again, also to augment all (noising, rotating etc.) and train again.我的问题是我想将 MNIST 上的所有图像大小调整为 14x14 并再次训练,同时增强所有图像(噪声、旋转等)并再次训练。 At the end, I want to be able to compare the accuracies of these three different dataset.最后,我希望能够比较这三个不同数据集的准确性。

Could you please help me to solve it?你能帮我解决吗? How to resize all images and how the model should change.如何调整所有图像的大小以及模型应如何更改。

Thanks!谢谢!

One way to resize images is using the scipy resize function:调整图像大小的一种方法是使用 scipy 调整大小功能:

from scipy.misc import imresize
img = imresize(yourimage, (14, 14))

But my real advice to you is that should take a look at the Kadenze course "Creative applications of deep learning".但我对你的真正建议是,应该看看 Kadenze 课程“深度学习的创造性应用”。 This is a notebook for lecture two: https://github.com/pkmital/CADL/blob/master/session-2/lecture-2.ipynb这是第二讲的笔记本: https : //github.com/pkmital/CADL/blob/master/session-2/lecture-2.ipynb

This course is really good at helping you understand using images and Tensorflow.本课程非常擅长帮助您理解使用图像和 Tensorflow。

What you need is some image processing library like OpenCV, PIL etc. If you are using the dataset downloaded from tensorflow, it will be a 3d array( array of 2d arrays(every image)) or have more dimensions depending on how it's stored (I'm not sure) you can treat numpy arrays as images and use them with any image processing library you like but make sure what datatype they are in and if it's compatible with the libraries you are using.您需要的是一些图像处理库,如 OpenCV、PIL 等。如果您使用从 tensorflow 下载的数据集,它将是一个 3d 数组(二维数组数组(每个图像))或具有更多维度,具体取决于它的存储方式(我不确定)您可以将 numpy 数组视为图像并将它们与您喜欢的任何图像处理库一起使用,但请确保它们的数据类型以及它是否与您正在使用的库兼容。

Also, tensorflow also has such functions if you want to keep it all in tensorflow.此外,如果您想将其全部保留在 tensorflow 中,tensorflow 也具有此类功能。

this post has an accepted answer. 这篇文章有一个公认的答案。

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

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