人工智能实践:从图像测试到云端应用
1. 外部图像测试
可以使用自己的图片来测试程序。例如用 iPhone 拍摄一张未分类的挂在墙上的连衣裙图片,通过 Mac 上的 Preview 将图片分辨率从 3024x3024 像素转换为 28x28 像素。虽然 28x28 像素的图片不够清晰,但与 Fashion - MNIST 数据库中的图片清晰度相当且尺寸更大。
以下是将原始 JPG 图片数据处理以适应 TensorFlow 图片格式的代码:
# read test dress image
imageName = "Dress28x28.JPG"
testImg = Image.open(imageName)
testImg.load()
data = np.asarray( testImg, dtype="float" )
data = tf.image.rgb_to_grayscale(data)
data = data/255.0
data = tf.transpose(data, perm=[2,0,1])
singlePrediction = model.predict(data,steps=1)
print ("Prediction Output")
print(singlePrediction)
print()
NumberElement = singlePrediction.argmax()
Element = np.amax(singlePrediction)
print ("Our Network has concluded that the file '"
+imageName+ "
超级会员免费看
订阅专栏 解锁全文
1000

被折叠的 条评论
为什么被折叠?



