Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Tensorflow 如何将层添加到图像识别卷积神经网络_Tensorflow_Machine Learning_Keras_Neural Network_Image Recognition - Fatal编程技术网

Tensorflow 如何将层添加到图像识别卷积神经网络

Tensorflow 如何将层添加到图像识别卷积神经网络,tensorflow,machine-learning,keras,neural-network,image-recognition,Tensorflow,Machine Learning,Keras,Neural Network,Image Recognition,我正在尝试建立一个卷积神经网络来检测情绪(一个简单的图像识别ai)。到目前为止,我已经能够将我的图像调整为32,32大小,以及将每个像素的RGB值添加到列表中。我现在该怎么办?我一直在尝试添加一个卷积层,但在实现过程中遇到了一些问题,我只是不确定隐藏层的实际构造应该是什么样子。使用google colab和MNIST数据集回答一个示例 步骤1: -进行导入,获取数据集,然后缩放并拆分为训练和测试。 -定义模型(我正在使用一个我发现非常好的模型,更简单的模型也可以使用) 步骤2: 编译和培训模型(

我正在尝试建立一个卷积神经网络来检测情绪(一个简单的图像识别ai)。到目前为止,我已经能够将我的图像调整为32,32大小,以及将每个像素的RGB值添加到列表中。我现在该怎么办?我一直在尝试添加一个卷积层,但在实现过程中遇到了一些问题,我只是不确定隐藏层的实际构造应该是什么样子。

使用google colab和MNIST数据集回答一个示例

步骤1: -进行导入,获取数据集,然后缩放并拆分为训练和测试。 -定义模型(我正在使用一个我发现非常好的模型,更简单的模型也可以使用)

步骤2: 编译和培训模型(也使用测试集在培训期间进行评估)

可选: 使用您自己的图像进行测试。这个上传部分是专门针对google colab的

uploaded = files.upload()
for fn in uploaded.keys():

  path = '/content/' + fn
  img = image.load_img(path, target_size=(28, 28),color_mode = "grayscale")
在我们预测之前,需要进行一些缩放和调整,以使测试图片“MNIST”

im2arr = np.array(img)
im2arr = im2arr-255.0
im2arr = im2arr*-1
image = im2arr
im2arr_scale = im2arr/255.0
im2arr = im2arr.reshape(1,28,28,1)
im2arr_scale = im2arr_scale.reshape(1,28,28,1)

y_pred = model.predict(im2arr)
y_pred2 = model.predict(im2arr_scale)



print("non scaled : " + str(np.argmax(y_pred)) + " probability: " + str(y_pred[0][np.argmax(y_pred)]))
print("scaled: " + str(np.argmax(y_pred2)) + " probability: " + str(y_pred2[0][np.argmax(y_pred2)]))
print (y_pred)
print (y_pred2)
绘制测试图像

plt.grid(False)
plt.gray()
plt.axis('off')
plt.imshow(image)
plt.show()

你的问题太模糊和笼统了。您想使用Keras还是TensorFlow?例如,有数百个教程介绍如何将其中任何一个用于图像对象识别,这与配置中的图像情感识别没有太大区别。只需指出“官方”教程:我目前正在使用tensorflow。更具体地说,我应该为我的图像识别软件使用一个已经构建好的已有模型,还是编写自己的模型?我发现大多数tensorflow教程都只关注MNIST,而没有提到如何实现自己的数据集。
im2arr = np.array(img)
im2arr = im2arr-255.0
im2arr = im2arr*-1
image = im2arr
im2arr_scale = im2arr/255.0
im2arr = im2arr.reshape(1,28,28,1)
im2arr_scale = im2arr_scale.reshape(1,28,28,1)

y_pred = model.predict(im2arr)
y_pred2 = model.predict(im2arr_scale)



print("non scaled : " + str(np.argmax(y_pred)) + " probability: " + str(y_pred[0][np.argmax(y_pred)]))
print("scaled: " + str(np.argmax(y_pred2)) + " probability: " + str(y_pred2[0][np.argmax(y_pred2)]))
print (y_pred)
print (y_pred2)
plt.grid(False)
plt.gray()
plt.axis('off')
plt.imshow(image)
plt.show()