Tensorflow:如何使用两种不同的模型

时间:2018-11-28 13:03:33

标签: python tensorflow machine-learning deep-learning

我是一名学习物体检测的学生。我设计了一个模型,可以在图像中找到图像的一部分并确定印版的类型。 使用两个检查点文件时出现问题。

with tf.Session(config=tf.ConfigProto(allow_soft_placement=True)) as sess:
    saver = tf.train.Saver()
    saver.restore(sess, model_from)
    print('Model_restored', model_from, tf.global_variables())
    image_path = sorted(image_path)
    def test_model(is_train):
        bbimg_list = []
        bbox_list = []
        is_finish = False
        index = 0
        while (not is_finish):

            batch_x, batch_y, is_finish = datas.next_batch_with_aid(is_train, batch, use_aid=use_aid_data, aid_ratio=use_aid_ratio)
            print(image_path[index])
            index+=1

            feed_dict = {X: batch_x, Y: batch_y, T: False, Aug: False}
            print(batch_x.shape)
            start = time.time()
            _bbox_proposal = sess.run(bbox_proposal, feed_dict)
            print(_bbox_proposal)
            bbox_list.append(_bbox_proposal)
            end = time.time()
            print('inference time ', end-start)
            print(batch_x[0].shape)

            bbimg_list.append(helper.save_image_bbox_with_gt(batch_x[0], _bbox_proposal, _bbox_proposal, resize_ratio=1))
            print(bbimg_list[-1])
            #displayer.save_image_list_attach(bbimg_list, env.DIR_SAVE_IMAGE + '_detect_'+str(is_train))
        return bbimg_list, bbox_list

    bbimg_list, bbox_list = test_model(True)
save_image_region.save_image_region(bbimg_list, env.DIR_SAVE_IMAGE +".jpg", bbox_list)

在以上来源中,车牌的位置以四个比率获得。 save_image_region裁剪具有4个坐标的图像并识别印版类型。

with tf.Session() as sess:

    saver = tf.train.Saver(tf.global_variables())
    print(os.listdir('/home/leehanbeen/PycharmProjects/TypeClassifier/model'))
    ckpt = tf.train.get_checkpoint_state('/home/leehanbeen/PycharmProjects/TypeClassifier/model')
    print(os.listdir('/home/leehanbeen/PycharmProjects/TypeClassifier/model'))
    print(ckpt.model_checkpoint_path)
    if ckpt and tf.train.checkpoint_exists(ckpt.model_checkpoint_path):
        saver.restore(sess, ckpt.model_checkpoint_path)
        print('Model restored')
    else:
        print("Model load failed.")
        exit()

    feed_dict = {X: np_image, P: 1.0}
    class_type = sess.run(argmax, feed_dict=feed_dict)

    draw.text(((int(width*np_bbox_list[0][2]+10), int(height*np_bbox_list[0][3]+3))), "Type: "+str(class_type)+" conf: "+str(np_bbox_list[0][4]))

return img

以上来源是save_image_region的一部分。如您所见,以上两个来源正在使用不同的模型。 但是,问题出在上述两个来源的下层来源。

NotFoundError (see above for traceback): Restoring from checkpoint failed. This is most likely due to a Variable name or other graph key that is missing from the checkpoint. Please ensure that you have not altered the graph expected based on the checkpoint. Original error:

它们中的每一个单独驱动时都运作良好,没有任何问题。 我该怎么办?

0 个答案:

没有答案