tensorflow 绘制图片

412 阅读1分钟
import tensorflow as tf
import numpy as np
import pandas as pd

/anaconda3/envs/py35/lib/python3.5/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
def _pre_read(img_filename):
    image = tf.read_file(img_filename)
    image = tf.image.decode_jpeg(image, channels=3)
    image = tf.image.rgb_to_grayscale(image)
    image = tf.image.resize_images(image, (600, 600))
    image = tf.reshape(image, [600, 600, 1])
    image = tf.image.per_image_standardization(image)
    return image

image = _pre_read("car.jpg")
sess = tf.Session()
image.shape
TensorShape([Dimension(600), Dimension(600), Dimension(1)])
type(image)
tensorflow.python.framework.ops.Tensor
image = sess.run(image)
image.shape
(600, 600, 1)
import matplotlib.pyplot as plt
%matplotlib inline
plt.imshow(image.reshape(600, 600))
<matplotlib.image.AxesImage at 0xb3482fc50>

from matplotlib.image import imread
img = imread("car.jpg")
plt.imshow(img)
<matplotlib.image.AxesImage at 0xb35d3f438>