Мне интересно, может ли кто-нибудь повторить эту проблему, и если ярлыки действительно неправильные, возможно, подскажет, что с этим делать?Я скачал набор данных с официального сайта, разархивировал его и попробовал прочитать digitStruct.mat.
мой код (при условии, что все данные находятся в папке data/train):
Код: Выделить всё
import os
from PIL import Image
from pymatreader import read_mat
import matplotlib.pyplot as plt
train_mat = read_mat('data/train/digitStruct.mat')
print(train_mat['digitStruct']['name'][52])
print(train_mat['digitStruct']['bbox'][52])
Код: Выделить всё
>>53.png
>>{'label': [9.0, 3.0], 'height': [84.0, 84.0], 'width': [59.0, 52.0], 'left': [160.0, 208.0], 'top': [34.0, 18.0]}
Код: Выделить всё
import cv2
from matplotlib import pyplot as plt
fig = plt.figure(figsize=(10, 7))
# Read the images using OpenCV (OpenCV loads images in BGR format)
image1 = cv2.imread('data/train/' + train_mat['digitStruct']['name'][0])
image2 = cv2.imread('data/train/' + train_mat['digitStruct']['name'][27])
image3 = cv2.imread('data/train/' + train_mat['digitStruct']['name'][52])
image4 = cv2.imread('data/train/' + train_mat['digitStruct']['name'][90])
# Convert the images from BGR to RGB format so Matplotlib can display them correctly
image1 = cv2.cvtColor(image1, cv2.COLOR_BGR2RGB)
image2 = cv2.cvtColor(image2, cv2.COLOR_BGR2RGB)
image3 = cv2.cvtColor(image3, cv2.COLOR_BGR2RGB)
image4 = cv2.cvtColor(image4, cv2.COLOR_BGR2RGB)
# Add the first image to the figure (top-left position)
plt.subplot(2, 2, 1) # 2 rows, 2 columns, first position
plt.imshow(image1)
plt.axis('off') # Hide the axis labels
plt.title(train_mat['digitStruct']['name'][0] + '\n' + str(train_mat['digitStruct']['bbox'][0]['label']))
# Add the second image to the figure (top-right position)
plt.subplot(2, 2, 2) # 2 rows, 2 columns, second position
plt.imshow(image2)
plt.axis('off') # Hide the axis labels
plt.title(train_mat['digitStruct']['name'][27] + '\n' + str(train_mat['digitStruct']['bbox'][27]['label']))
# Add the third image to the figure (bottom-left position)
plt.subplot(2, 2, 3) # 2 rows, 2 columns, third position
plt.imshow(image3)
plt.axis('off') # Hide the axis labels
plt.title(train_mat['digitStruct']['name'][52] + '\n' + str(train_mat['digitStruct']['bbox'][52]['label']))
# Add the fourth image to the figure (bottom-right position)
plt.subplot(2, 2, 4) # 2 rows, 2 columns, fourth position
plt.imshow(image4)
plt.axis('off') # Hide the axis labels
plt.title(train_mat['digitStruct']['name'][90] + '\n' + str(train_mat['digitStruct']['bbox'][90]['label']))
Подробнее здесь: https://stackoverflow.com/questions/792 ... hn-dataset
Мобильная версия