目前,我正在通过使用Keras创建一个简单的图像分类器(带有Tensorflow后端)来向自己传授机器学习的基础知识。该模型将(灰度)图像分类为猫或非猫。
我的模型在这个任务上相对较好,所以我现在想看看它是否能够生成图像,并将其归类为猫。
我尝试以一种简单的方式开始这项工作,方法是创建一个与图像形状相同的随机数组,每个索引中都包含随机数:
from random import randint
json_file = open('model.json', 'r')
loaded_model_json = json_file.read()
json_file.close()
model = model_from_json(loaded_model_json)
model.load_weights("model_weights.h5")
confidence = 0.0
thresholdConfidence = 0.6
while confidence < thresholdConfidence:
img_array = np.array([[[randint(0, 255) for z in range(1)] for y in range(64)] for x in range(64)])
img_array = img_array.reshape((1,) + img_array.shape)
confidence = model.predict(img_array)这个方法显然一点都不好,因为它只是创建随机的东西,并且可能永远运行。该模型能否以某种方式反向运行,告诉它数组是100% cat,并让它预测图像的数组表示是什么?
感谢您的阅读。
这是我在StackOverflow上的第一篇文章,所以如果我做错了什么,请告诉我!
发布于 2018-11-19 15:46:53
https://stackoverflow.com/questions/53377681
复制相似问题