读取图片生成标签

import os
from skimage import io,transform
import glob
import numpy as np

path="flower/";
h=224;
w=224;
c=3;

pathname=[path+x for x in os.listdir(path)];
print(pathname);
count=0;
imgs=[];
labels=[];
for idx,dirname in enumerate(pathname):
	for i in glob.glob(dirname+"/*.jpg"):
		count+=1;
		print("Reading (%s,%d):"%(i,count));
		img=io.imread(i);
		img=transform.resize(img,(h,w,c));
		imgs.append(img);
		labels.append(idx);

images=np.asarray(imgs,np.float32);
labels=np.asarray(labels,np.int32);
print(images);
print(labels);
num_samples=images.shape[0];
print(num_samples);
arr=np.arange(num_samples);
print("arr=",arr);
np.random.shuffle(arr);
images=images[arr];
labels=labels[arr];
print(labels);

你可能感兴趣的:(深度学习通用代码)