33、人工智能实践:从图像测试到云端应用

人工智能实践:从图像测试到云端应用

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+ "
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值