所以我有一堆图像(PNG),它们的名称可用作标签。关于我如何拍摄这些图像并创建像MNIST IDX这样的数据集,是否有工具或示例。
有很多关于如何阅读它们的示例,但是没有关于如何创建它们的示例。
任何帮助将不胜感激!
我正在努力在iOS上运行MNIST的CNN推理.Apple开始提供一个很好的代码示例. https://developer.apple.com/library/content/samplecode/MPSCNNHelloWorld/Introduction/Intro.html#//apple_ref/doc/uid/TP40017482-Intro-DontLinkElementID_2
但是,当我尝试使用MPS 实现更复杂的CNN模型(例如https://github.com/fchollet/keras/blob/master/examples/mnist_cnn.py)时,我发现没有"Flatten"类过滤.
我查看了MPS框架,找到了重塑或更改维度的功能,但我找不到合适的维度.(例如,MPSImageConversion
似乎仅用于转换颜色,而不是用于维度.
如果有人知道Flatten的过滤器或如何将多维图像转换为1D图像,请告诉我.
我使用tensorflow导入一些MNIST输入数据.我按照本教程... https://www.tensorflow.org/get_started/mnist/beginners
我正在导入它们......
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("/tmp/data/", one_hot=True)
Run Code Online (Sandbox Code Playgroud)
我希望能够显示训练集中的任何图像.我知道图像的位置是mnist.train.images
,所以我尝试访问第一个图像并显示它...
with tf.Session() as sess:
#access first image
first_image = mnist.train.images[0]
first_image = np.array(first_image, dtype='uint8')
pixels = first_image.reshape((28, 28))
plt.imshow(pixels, cmap='gray')
Run Code Online (Sandbox Code Playgroud)
我试图将图像转换为28乘28的numpy数组,因为我知道每个图像是28 x 28像素.
但是,当我运行代码时,我得到的是以下内容......
显然我做错了什么.当我打印出矩阵时,一切看起来都很好,但我认为我错误地重塑了它.
我一直在尝试使用VGG / Inception对MNIST数据集使用转移学习。但是,这两个网络都接受尺寸至少为224x224x3的图像。如何将28x28x1 MNIST图像缩放到224x224x3,以进行传输学习?
我已经按照TensorFlow MNIST Estimator教程进行了训练,并且训练了我的MNIST模型.
它似乎工作正常,但如果我在Tensorboard上可视化它我看到一些奇怪的东西:模型所需的输入形状是100 x 784.
这是一个屏幕截图:正如您在右侧框中看到的,预期输入大小为100x784.
我以为我会看到?x784那里.
现在,我确实在训练中使用100作为批量大小,但在Estimator模型函数中我还指定了输入样本量的大小是可变的.所以我期待?x 784将在Tensorboard中显示.
input_layer = tf.reshape(features["x"], [-1, 28, 28, 1], name="input_layer")
Run Code Online (Sandbox Code Playgroud)
我尝试在具有不同批量大小的同一模型上使用estimator.train和estimator.evaluate方法(例如50),并使用Estimator.predict方法一次传递一个样本.在这些情况下,一切似乎都很好.
相反,如果我尝试使用模型而不通过Estimator接口,我确实会遇到问题.例如,如果我冻结我的模型并尝试在GraphDef中加载它并在会话中运行它,如下所示:
with tf.gfile.GFile("/path/to/my/frozen/model.pb", "rb") as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
with tf.Graph().as_default() as graph:
tf.import_graph_def(graph_def, name="prefix")
x = graph.get_tensor_by_name('prefix/input_layer:0')
y = graph.get_tensor_by_name('prefix/softmax_tensor:0')
with tf.Session(graph=graph) as sess:
y_out = sess.run(y, feed_dict={x: 28_x_28_image})
Run Code Online (Sandbox Code Playgroud)
我将得到以下错误:
ValueError:无法为Tensor'前缀/ input_layer:0'提供形状值(1,28,28,1),其形状为'(100,28,28,1)'
这让我很担心,因为在生产中我需要冻结,优化和转换我的模型以在TensorFlow Lite上运行它们.所以我不会使用Estimator接口.
我错过了什么?
我有两个相同的神经网络在两台独立的计算机上运行(以减少训练网络所需的时间),每个神经网络都有一个完整数据集(MNIST)的子集.
我的问题是; 我可以将两个网络的两个权重矩阵组合成一个矩阵,同时保持适当的精度吗?我看过几篇关于"批量"或"随机梯度下降"的文章,但我不认为这适用于我的情况.
如果这是可能的,你还可以提供一些伪代码吗?任何输入都很有价值!
谢谢,
我是深度学习的初学者,我正在 keras 中研究 mnist 数据集。
我使用归一化作为
tf.keras.utils.normalize(x_train, axis = 1)
Run Code Online (Sandbox Code Playgroud)
我不明白轴参数是什么意思。你能帮我解决这个问题吗?
我正在尝试在我的计算机中实现此代码,我面临的问题是运行以下代码时出现错误:
fashion_mnist = keras.datasets.fashion_mnist
(X_train_full, y_train_full), (X_test, y_test) = (fashion_mnist.load_data())
X_valid, X_train = X_train_full[:5000], X_train_full[5000:]
y_valid, y_train = y_train_full[:5000], y_train_full[5000:]
Run Code Online (Sandbox Code Playgroud)
错误:
~\Anaconda3\lib\site-packages\tensorflow_core\python\keras\utils\data_utils.py in get_file(fname, origin, untar, md5_hash, file_hash, cache_subdir, hash_algorithm, extract, archive_format, cache_dir)
251 urlretrieve(origin, fpath, dl_progress)
252 except HTTPError as e:
--> 253 raise Exception(error_msg.format(origin, e.code, e.msg))
254 except URLError as e:
255 raise Exception(error_msg.format(origin, e.errno, e.reason))
Exception: URL fetch failure on https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-labels-idx1-ubyte.gz: 403 -- Forbidden
Run Code Online (Sandbox Code Playgroud)
但是如果我尝试单独下载数据,它不会给出禁止的错误,我尝试加载数据而不从谷歌下载,但又出现了另一个错误
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-13-68fe7d0ac27a> …
Run Code Online (Sandbox Code Playgroud) 我正在用一个基本示例验证我的 TensorFlow (v2.2.0)、Cuda (10.1) 和 cudnn (libcudnn7-dev_7.6.5.32-1+cuda10.1_amd64.deb) 并且我得到了奇怪的结果......
在Keras 中运行以下示例时,如https://keras.io/examples/mnist_cnn/所示,我得到了 ~99% acc @validation。当我调整通过 TensorFlow 运行的导入时,我只得到 86%。
我可能忘记了什么。
使用 tensorflow 运行:
from __future__ import print_function
import tensorflow as tf
from tensorflow.keras.datasets import mnist
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout, Flatten
from tensorflow.keras.layers import Conv2D, MaxPooling2D
from tensorflow.keras import backend as K
batch_size = 128
num_classes = 10
epochs = 12
# input image dimensions
img_rows, img_cols = 28, 28
# the data, split between train and …
Run Code Online (Sandbox Code Playgroud) import tensorflow as tf
import random
import numpy as np
x= tf.placeholder('float')
x=tf.reshape(x,[-1,28,28,1])
with tf.Session() as sess:
x1 = np.asarray([random.uniform(0,1) for i in range(784)])
result = sess.run(x, feed_dict={x: x1})
print(result)
Run Code Online (Sandbox Code Playgroud)
我在重整形时使用mnist数据时遇到了一些问题,但是这个问题是我的问题的简化版本...为什么此代码实际上不起作用?
表明
“ ValueError:无法为具有形状'(?,28,28,1)'的张量'Reshape:0'输入形状(784,)的值。“
我该怎么解决?
mnist ×10
tensorflow ×7
python ×6
keras ×4
numpy ×3
flatten ×1
ios ×1
java ×1
matplotlib ×1
matrix ×1
metal ×1
optimization ×1
reshape ×1
testing ×1