2017-03-17 32 views
0

我管理使用下面的代碼來顯示圖像:Tensorflow v0.12圖像不displying調整後

import os 
import tensorflow as tf 
from tensorflow.python.framework import ops 
from tensorflow.python.framework import dtypes 
import numpy as np 
import glob 
import fnmatch 
import matplotlib.pyplot as plt 
from PIL import Image 

def test1(path): 

    filename_queue = tf.train.string_input_producer(tf.train.match_filenames_once(path)) 

    image_reader = tf.WholeFileReader() 

    label, image_file = image_reader.read(filename_queue) 

    image = tf.image.decode_jpeg(image_file,3) 

    print(image)  

    image = tf.image.resize_images(image, [224 , 224]) 

    print(image) 

    with tf.Session() as sess: 

     tf.global_variables_initializer().run() 

     coord = tf.train.Coordinator() 
     threads = tf.train.start_queue_runners(coord=coord) 

     for i in range(1): 
      img = image.eval()  

     Image.fromarray(np.asarray(img)).show() 


     coord.request_stop() 
     coord.join(threads) 

    sess.close() 

if __name__== "__main__": 

    test1("./data/test1/1099.jpg") 

給它:

import os 
import tensorflow as tf 
from tensorflow.python.framework import ops 
from tensorflow.python.framework import dtypes 
import numpy as np 
import glob 
import fnmatch 
import matplotlib.pyplot as plt 
from PIL import Image 

def test1(path): 

    filename_queue = tf.train.string_input_producer(tf.train.match_filenames_once(path)) 

    image_reader = tf.WholeFileReader() 

    label, image_file = image_reader.read(filename_queue) 

    image = tf.image.decode_jpeg(image_file,3) 

    print(image)  


    with tf.Session() as sess: 

     tf.global_variables_initializer().run() 

     coord = tf.train.Coordinator() 
     threads = tf.train.start_queue_runners(coord=coord) 

     for i in range(1): 
      img = image.eval()  

     Image.fromarray(np.asarray(img)).show() 


     coord.request_stop() 
     coord.join(threads) 

    sess.close() 

if __name__== "__main__": 

    test1("./data/test1/1099.jpg") 
然而

當我使用下面的代碼調整圖像大小以下錯誤信息:

raise TypeError(「無法處理此數據類型」) TypeError:無法處理此數據類型

感謝

+0

那麼什麼是影像D型?打印(image.dtype)或打印(tf.DType(圖片)) – Steven

+0

@Steven感謝您回覆我的問題。 print(image.dtype)產生張量(「DecodeJpeg:0」,shape =(?,?3),dtype = uint8) ,同時print(tf.DType(image))產生TypeError :int()參數必須是一個字符串或數字,而不是'張量' – dragon

+0

很高興你把它修好了。您應該接受您的答案,以便您可以結束該問題。 – Steven

回答

0

管理來解決它

import os 
import tensorflow as tf 
from tensorflow.python.framework import ops 
from tensorflow.python.framework import dtypes 
import numpy as np 
import glob 
import fnmatch 
import matplotlib.pyplot as plt 
from PIL import Image 

def test1(path): 

    filename_queue = tf.train.string_input_producer(tf.train.match_filenames_once(path)) 

    image_reader = tf.WholeFileReader() 

    label, image_file = image_reader.read(filename_queue) 

    image = tf.image.decode_jpeg(image_file,3) 

    print(image)  

    image = tf.image.resize_images(image, [224 , 224]) 

    print(image) 

    with tf.Session() as sess: 

     tf.global_variables_initializer().run() 

     coord = tf.train.Coordinator() 
     threads = tf.train.start_queue_runners(coord=coord) 

     for i in range(1): 
      img = image.eval()  

     Image.fromarray(np.asarray(img.astype(np.uint8))).show() 


     coord.request_stop() 
     coord.join(threads) 

    sess.close() 

if __name__== "__main__": 

    test1("./data/test1/1099.jpg") 

謝謝大家:)