Closed LukeALee closed 7 years ago
使用第五章中的方法即可实现save与restore,但需要注意的是如果需要保存训练好的模型用于直接分类,每次重新巡行不能使用dict类型的result(即书中例子构造的的图片)而要使用Orderdict(即有序字典),否则每次lable的顺序不一致而导致下次用的时候预测的分类和ground_truth的分类不一致,那么正确率无论如何都会很低了
请问书友是否已经实现了,在训练以后将整个模型保存并使用保存好的模型预测新的图片呢?
你好,已经实现了,具体的代码因为要用到某些工作上所以目前不太方便公开,实现的方式就是如之前我所说的,首先将代码中的result重新使用Orderdict的类型构建,自己编写一个函数生成bottleneck_values, 然后预测时使用该函数生成需要预测的图片的bottleneck_values,定义image_order_step = tf.arg_max(final_tensor, 1), 使用sess.run运行该tensor,其返回值就是在result列表中该图片所属分类的序号。
至于保存和恢复的方式和书上说的并没有什么区别。
谢谢
我将以下代码从
main
函数中提取出来并实现模型的训练与保存: `def train(bottleneck_tensor, jpeg_data_tensor): image_lists = create_image_lists(TEST_PERCENTAGE, VALIDATION_PERCENTAGE) n_classes = len(image_lists.keys())使用以下代码尝试恢复模型并使用测试图片再次预测测试图片的分类, `def image_Classfier(bottleneck_tensor, jpeg_data_tensor):
`def main(): graph_def = load_inception_v3() bottleneck_tensor, jpeg_data_tensor = tf.import_graph_def( graph_def, return_elements=[BOTTLENECK_TENSOR_NAME, JPEG_DATA_TENSOR_NAME]) train(bottleneck_tensor, jpeg_data_tensor) image_Classfier(bottleneck_tensor, jpeg_data_tensor)
if name == 'main': main()` 但是失败了,似乎并没能将保存的模型正确的恢复,请问我哪里做错了,又该如何实现?