早上好,知更鸟 2022-05-04 21:28 采纳率: 80%
浏览 11
已结题

tensorflow如何加载模型

取出来的模型默认是model.ckpt-0,但我想换一个模型,怎么换

 logs_train_dir = './cat_dog/saveNet/'
    # 定义saver
    saver = tf.train.Saver()

    with tf.Session() as sess:

        print("从指定的路径中加载模型。。。。")
        # 将模型加载到sess 中
        ckpt = tf.train.get_checkpoint_state(logs_train_dir)
        if ckpt and ckpt.model_checkpoint_path:
            global_step = ckpt.model_checkpoint_path.split('/')[-1].split('-')[-1]
            saver.restore(sess, ckpt.model_checkpoint_path)
            print('模型加载成功, 训练的步数为 %s' % global_step)
        else:
            print('模型加载失败,,,文件没有找到')
            # 将图片输入到模型计算
        prediction = sess.run(logit, feed_dict={x: image_array})
        # 获取输出结果中最大概率的索引
        max_index = np.argmax(prediction)
        if max_index == 0:
            print('猫的概率 %.6f' % prediction[:, 0])
        else:
            print('狗的概率 %.6f' % prediction[:, 1])
        # 测试

evaluate_one_image()

  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 5月12日
    • 创建了问题 5月4日