def load_data(self, filename): """ load_data """ image = process_image(filename, 224) tensor = core.PaddleTensor() print(len(image)) tensor.shape = [1, 3, 224, 224] tensor.data = core.PaddleBuf(image.tolist()) tensor.dtype = core.PaddleDType.FLOAT32 tensor.lod = [[0L, 1L]] return [tensor]
def load_data(self, filename): """ load_data """ image = process_image(filename, 224) image_tensor = core.PaddleTensor() image_tensor.name = 'image' image_tensor.shape = [1, 3, 224, 224] image_tensor.data = core.PaddleBuf(image.tolist()) image_tensor.dtype = core.PaddleDType.FLOAT32 #im-info im_info_tensor = core.PaddleTensor() im_info_tensor.shape = [1, 3] im_info_tensor.name = "im_info" im_info_tensor.data = core.PaddleBuf([224., 224., 1.0]) im_info_tensor.dtype = core.PaddleDType.FLOAT32 return [image_tensor, im_info_tensor]
def images_to_tensor(self): images = [] for file in sorted(os.listdir('data/jaffe_images_small')): if (file != '.DS_Store'): image = matplotlib.image.imread('data/jaffe_images_small/' + file) # read images if (len(np.shape(image)) > 2): image = image[:, :, 0] image = image.tolist() # convert to list ? image = imresize(image, (48, 48)) # compress to 48*48 pixel images.append(image) image_tensor = np.array(images) image_tensor = image_tensor - np.mean(image_tensor, axis=0) # ??? image_tensor = image_tensor.reshape( 213, 48, 48, 1) # 213 images in data/jaffe_images_small, each one 48*48 pixel return image_tensor
def load_data(self, filename): """ load_data """ image = process_image(filename, 224) image_tensor = core.PaddleTensor() image_tensor.name = 'image' image_tensor.shape = [1, 3, 224, 224] image_tensor.data = core.PaddleBuf(image.tolist()) image_tensor.dtype = core.PaddleDType.FLOAT32 #image_shspe im_shape_tensor = core.PaddleTensor() im_shape_tensor.shape = [1, 2] im_shape_tensor.name = "im_shape" im_shape_tensor.data = core.PaddleBuf([224, 224]) im_shape_tensor.dtype = core.PaddleDType.INT32 #im_id im_id_tensor = core.PaddleTensor() im_id_tensor.shape = [1, 1] im_id_tensor.name = "im_id" im_id_tensor.data = core.PaddleBuf([1,]) im_id_tensor.dtype = core.PaddleDType.INT32 return [image_tensor, im_shape_tensor]
import numpy as np from scipy.misc import imresize import matplotlib.image import matplotlib.pyplot image = matplotlib.image.imread('data/jaffe_images_small/NA.SA2.206.tiff') print image #matplotlib.pyplot.imshow(image) image = image.tolist() image = imresize(image, (48, 48)) print image matplotlib.pyplot.imshow(image)