# -*- coding: utf-8 -*-
import tensorflow as tf
import cv2
import numpy as np
d0=cv2.imread("000000.jpg")
d1=cv2.imread("000001.jpg")
d2=cv2.imread("000002.jpg")
d3=cv2.imread("000003.jpg")
#图片维度信息 [384,768,3]
d0=d0[np.newaxis, :, :, :]
d1=d1[np.newaxis, :, :, :]
d2=d2[np.newaxis, :, :, :]
d3=d3[np.newaxis, :, :, :]
#扩维 [1,384,768,3]
data_bacth=tf.concat([d0,d1,d2,d3],axis=0)
#[4,384,768,3]
#[i,0,0,0]代表我要去data_batch中的第i个图片
img=tf.slice(data_bacth, [1,0,0,0], [1, -1, -1, -1])
img=tf.squeeze(img)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
data,img2=sess.run([data_bacth,img])
print data.shape
print img2.shape
cv2.imshow("00",img2)
cv2.waitKey(0)
四张图片如下,
img=tf.slice(data_bacth, [0,0,0,0], [1, -1, -1, -1])
显示的第0张图片为:
img=tf.slice(data_bacth, [3,0,0,0], [1, -1, -1, -1])
显示的第3张图片为: