Skip to content

Instantly share code, notes, and snippets.

@lartpang
Last active October 9, 2018 09:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lartpang/bda9bdba0cc393b2ae5dc0908237e482 to your computer and use it in GitHub Desktop.
Save lartpang/bda9bdba0cc393b2ae5dc0908237e482 to your computer and use it in GitHub Desktop.
获取文件夹下文件名/读取放缩图片/存储数据
# 获取文件名
import os
all_file = []
def file_name(path):
for file_name in os.listdir(path):
all_file.append(file_name)
path = 'test/'
file_name(path)
num_image_train = len(all_file)
# 导入训练数据
x_train = np.zeros((num_image_train, 224, 224, 3))
for i in range(num_image_train):
img = Image.open(path + all_file[i])
img_resize = img.resize((224, 224))
x_train[i] = np.array(img_resize)
np.save("x_train.npy", x_train)
print("训练数据导入完毕")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment