plt.figure(figsize=(12, 12))
for i, class_name in enumerate(classes.values()):
class_subset = raw_data.loc[raw_data.class_name == class_name].sample(n=4)
img_names = class_subset.filename.to_list()
for j, img in enumerate(img_names):
image = cv2.imread(os.path.join(img_dir, img))
## convert image to RGB
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
## subplot variables - (# of rows, # of columns, iterate through locations on grid)
plt.subplot(8, 4, 4 * i + j + 1)
plt.imshow(image_rgb, aspect=1)
## label with filename and diagnosis
plt.xlabel('{}'.format(class_name))
plt.tight_layout()
有人定义错误并解码此代码。
该错误表明变量“classes”(您试图在第 3 行中枚举)不存在。