我正在读取2个文件夹中的图像然后附加它。我使用以下代码来执行此操作。
import cv2
import os
path = "C:/Users/username/Desktop/Data/Val1"
def load_images_from_folder(folder):
images = []
labels = []
for filename in os.listdir(folder):
img = cv2.imread(os.path.join(folder,filename))
label = path.split(os.path.sep)[-1].split("/")[-1]
if img is not None:
images.append(img)
labels.append(label)
return images, labels
train_data_all_pos = load_images_from_folder("C:/Users/username/Desktop/Data/Val1")
train_features_pos = train_data_all_pos[0]
train_labels_pos = train_data_all_pos[1]
print(len(train_features_pos))
print(len(train_labels_pos))
path = "C:/Users/username/Desktop/Data/Val2"
train_data_all_neg = load_images_from_folder("C:/Users/username/Desktop/Data/Val2")
train_features_neg = train_data_all_neg[0]
train_labels_neg = train_data_all_neg[1]
print(len(train_features_neg))
print(len(train_labels_neg))
train_features = np.append(train_features_pos, train_features_neg)
train_labels = np.append(train_labels_pos, train_labels_neg)
print(len(train_features))
print(len(train_labels))
Val1
中的总图片数为163,Val2
的总图片数为340.但是当我追加时,对于标签我获得了503,但是对于我要获得的功能数百万的价值。每个图像尺寸为64 * 64 * 3。因此,我得到的总价值是6180864
,这只是64 * 64 * 3 * 503。
我遇到的问题是功能和图像的尺寸不一样。我在这里犯了一个错误,但不知道如何纠正它。