有時需要讀取jpg圖像的長和寬,tensorflow提供了很好的支持
直接上示例
1
2
3
4
5
6
7
8
9
|
decode_jpeg_data = tf.placeholder(dtype = tf.string) decode_jpeg = tf.image.decode_jpeg(decode_jpeg_data, channels = 3 ) image_data = tf.gfile.FastGFile( "C:/Users/shenwei/Desktop/timg.jpg" , 'rb' ).read() print ( len (image_data)) with tf.Session() as sess: image = sess.run(decode_jpeg,feed_dict = {decode_jpeg_data: image_data}) print (image.shape[ 0 ]) print (image.shape[ 1 ]) |
注意看image,shape是(800,800,3) 表示長為800 寬為800 3個通道
補充知識:TensorFlow中multiply和matmul的區別
TensorFlow中multiply是兩個矩陣之間對應元素相乘,可以是矩陣*矩陣,也可以是矩陣*向量或是矩陣*一個數;
而matmul則是矩陣相乘,是矩陣行*矩陣列,即a x b。如下所示:
這個是multiply,矩陣對應元素相乘
這個是matmul,即行 x 列
以上這篇tensorflow之讀取jpg圖像長和寬實例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持服務器之家。
原文鏈接:https://blog.csdn.net/g0415shenw/article/details/86488522