tensorflow display and interpret blueprints

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/qq_36249824/article/details/102759806
#!/usr/bin/env python
# @Time    : 2019/10/26 11:59
# @File    : f102601.py
import pylab

import tensorflow as tf



import numpy as np

import  matplotlib.pyplot as plt

image_raw_data_jpg= tf.io.gfile.GFile(r'C:\Users\Administrator\Desktop\test\cat\c1.jpg','rb').read()

with tf.compat.v1.Session() as sess:        #这种情况下不能用tensor.numpy()
    img= tf.image.decode_jpeg(image_raw_data_jpg,channels=3)
    #开重新保存的,说明下图片是网上下载的数据集,于是我猜测可能图片本身就是多通道的,但是由于收集图片的人使用

    #编辑器的问题,导致图像不是真实的通道,试将decode_jpeg里的channel=1改为channel=3
    # img= tf.image.convert_image_dtype(img_data_jpg,dtype=tf.uint8)
    plt.figure() #图像显示
    # img = tf.image.decode_jpeg(img)
    # img_data_jpg=img.numpy()
    # img_data_jpg=tf.reshape(img_data_jpg,[100,200])
    print((img.eval()).shape)
    plt.imshow(img.eval()) #调用.eval()该张量对象应返回一个numpy ndarray
    plt.show()

 

Guess you like

Origin blog.csdn.net/qq_36249824/article/details/102759806