更新时间:2023-02-15 GMT+08:00
分享

使用模型

  1. 用训练好的模型预测测试集中的某个图片属于什么类别,先显示这个图片,命令如下。

    1
    2
    3
    # display a test image
    plt.figure()
    plt.imshow(test_images[9])
    
    图1 显示用以测试的图片

  2. 查看预测结果,命令如下。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    # Grab an image from the test dataset.
    img = test_images[9]
    # Add the image to a batch where it's the only member.
    img = (np.expand_dims(img,0))
    # make prediction
    probability_model = tf.keras.Sequential([model, 
                                             tf.keras.layers.Softmax()])
    predictions_single = probability_model.predict(img)
    class_names[np.argmax(predictions_single[0])]
    
    图2 查看预测结果
    • 当前只对python3做了优化,python2下无法直接运行Jupyter Notebook。
    • CodeArts IDE Online暂不支持GPU加速,建议安装tensorflow-cpu减小磁盘占用,并加快安装速度。
    • 鲲鹏镜像暂时无法安装TensorFlow,敬请期待后续更新。

分享:

    相关文档

    相关产品