Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix loading file and image processing in CIFAR #284

Merged
merged 5 commits into from
Jun 10, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
-

### Fixed
-
- Image processing and file upload in CIFAR (<https://github.com/openvinotoolkit/datumaro/pull/284>)
zhiltsov-max marked this conversation as resolved.
Show resolved Hide resolved

### Security
-
Expand Down
15 changes: 9 additions & 6 deletions datumaro/plugins/cifar_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def _load_items(self, path):
# 'filenames': list
# 'labels': list
with open(path, 'rb') as anno_file:
annotation_dict = pickle.load(anno_file)
annotation_dict = pickle.load(anno_file, encoding='latin1')

labels = annotation_dict.get('labels', [])
filenames = annotation_dict.get('filenames', [])
Expand All @@ -94,11 +94,13 @@ def _load_items(self, path):
if 0 < len(images_data):
image = images_data[i]
if size is not None and image is not None:
image = image.reshape(size[i][0],
size[i][1], 3).astype(np.uint8)
image = image.reshape(3, size[i][0],
size[i][1]).astype(np.uint8)
image = np.transpose(image, (1, 2, 0))
elif image is not None:
image = image.reshape(CifarPath.IMAGE_SIZE,
CifarPath.IMAGE_SIZE, 3).astype(np.uint8)
image = image.reshape(3, CifarPath.IMAGE_SIZE,
CifarPath.IMAGE_SIZE).astype(np.uint8)
image = np.transpose(image, (1, 2, 0))

items[item_id] = DatasetItem(id=item_id, subset=self._subset,
image=image, annotations=annotations)
Expand Down Expand Up @@ -150,7 +152,8 @@ def apply(self):
data.append(None)
else:
image = image.data
data.append(image.reshape(-1).astype(np.uint8))
data.append(np.transpose(image, \
(2, 0, 1)).reshape(-1).astype(np.uint8))
if image.shape[0] != CifarPath.IMAGE_SIZE or \
image.shape[1] != CifarPath.IMAGE_SIZE:
image_sizes[len(data) - 1] = (image.shape[0], image.shape[1])
Expand Down
Binary file modified tests/assets/cifar_dataset/data_batch_1
Binary file not shown.
Binary file modified tests/assets/cifar_dataset/test_batch
Binary file not shown.
5 changes: 5 additions & 0 deletions tests/test_cifar_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ def test_can_import(self):
DatasetItem(id='image_4', subset='test',
image=np.ones((32, 32, 3)),
annotations=[Label(2)]
),
DatasetItem(id='image_5', subset='test',
image=np.array([[[1., 2., 3.], [4., 5., 6.]],
[[1., 2., 3.], [4., 5., 6.]]]),
annotations=[Label(3)]
zhiltsov-max marked this conversation as resolved.
Show resolved Hide resolved
)
], categories=['airplane', 'automobile', 'bird', 'cat'])

Expand Down