【发布时间】:2022-01-11 09:46:20
【问题描述】:
大家好,目前正在学习深度学习和机器学习
我也在研究代码的同时阅读了一些 github 的解释
但没有解释他们如何从这段代码中分离出测试数据(底部有注释# declare data for training and validation, if you want, you can seperate testset from this
# 1. Creating Datasets
# define temporary empty list for load
data = []
label = []
Totalnb = 0
# Load Dataset
for i in range(n_labels):
nb = 0
# Counting datasets in each labels
for root, dirs, files in os.walk('Progress/DataLatihBaru/' + str(i+1)): # set directory
for name in dirs:
nb = nb + 1
print(i,"Label number of Dataset is:",nb)
Totalnb = Totalnb + nb
# by Counting size, cross subfolder and read image data, resize image, and append list
for j in range(nb):
temp = []
for k in range(timesteps):
# name = 'NormalizedCascaded/' + str(i+1) + '/' + str(j+1) + '/' + str(k+1) + '.jpg'
name = 'Progress/DataLatihBaru/' + str(i+1) + '/' + str(j+1) + '/' + 'a (' + str(k+1) + ')' + '.jpg'
img = cv2.imread(name)
res = cv2.resize(img, dsize=(img_col, img_row), interpolation=cv2.INTER_CUBIC)
temp.append(res)
label.append(i)
data.append(temp)
print("Total Number of Data is",Totalnb)
# Convert List to numpy array, for Keras use
Train_label = np.eye(n_labels)[label] # One-hot encoding by np array function
Train_data = np.array(data)
print("Dataset shape is",Train_data.shape, "(size, timestep, column, row, channel)")
print("Label shape is",Train_label.shape,"(size, label onehot vector)")
# shuffling dataset for input fit function
# if don`t, can`t train model entirely
x = np.arange(Train_label.shape[0])
np.random.shuffle(x)
# same order shuffle is needed
Train_label = Train_label[x]
Train_data = Train_data[x]
# declare data for training and validation, if you want, you can seperate testset from this
X_train=Train_data[0:Totalnb,:]
Y_train=Train_label[0:Totalnb]
谁能帮助我,以便我能理解我应该如何通过一点解释将数据分离到测试的那部分?
非常感谢!
【问题讨论】:
标签: python numpy tensorflow deep-learning