Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Load Numpy arrays of incompatible dtypes #1507

Draft
wants to merge 17 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 9 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
8 changes: 7 additions & 1 deletion flash/core/data/utilities/loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,13 @@ def _load_image_from_image(file):


def _load_image_from_numpy(file):
return Image.fromarray(np.load(file).astype("uint8")).convert("RGB")
try:
return Image.fromarray(np.load(file).astype("uint8", casting="safe")).convert("RGB")
except TypeError as e:
import warnings

warnings.warn(str(e) + ". Converting to float instead.", RuntimeWarning)
return Image.fromarray(np.load(file).astype(float, casting="safe")).convert("RGB")


def _load_spectrogram_from_image(file):
Expand Down
1 change: 1 addition & 0 deletions train_annotations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"annotations": [{"area": 50, "bbox": [10, 20, 5, 10], "num_keypoints": 2, "keypoints": [10, 15, 2, 20, 30, 2], "category_id": 1, "id": 1, "image_id": 1, "iscrowd": 0}, {"area": 100, "bbox": [20, 30, 10, 10], "num_keypoints": 2, "keypoints": [20, 30, 2, 30, 40, 2], "category_id": 2, "id": 2, "image_id": 2, "iscrowd": 0}, {"area": 125, "bbox": [10, 20, 5, 25], "num_keypoints": 2, "keypoints": [10, 15, 2, 20, 45, 2], "category_id": 1, "id": 3, "image_id": 3, "iscrowd": 0}], "categories": [{"id": 1, "name": "cat", "supercategory": "cat", "keypoints": ["left ear", "right ear"]}, {"id": 2, "name": "dog", "supercategory": "dog", "keypoints": ["left ear", "right ear"]}], "images": [{"file_name": "image_1.png", "height": 64, "width": 64, "id": 1}, {"file_name": "image_2.png", "height": 64, "width": 64, "id": 2}, {"file_name": "image_3.png", "height": 64, "width": 64, "id": 3}]}
souravraha marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions train_annotations/image_1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<annotation><filename>image_1.png</filename><path>image_1.png</path><source><database>example</database></source><size><width>64</width><height>64</height><depth>3</depth></size><object><name>cat</name><pose>Unspecified</pose><truncated>0</truncated><difficult>0</difficult><occluded>0</occluded><bndbox><xmin>10</xmin><xmax>15</xmax><ymin>20</ymin><ymax>30</ymax></bndbox></object></annotation>
1 change: 1 addition & 0 deletions train_annotations/image_2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<annotation><filename>image_2.png</filename><path>image_2.png</path><source><database>example</database></source><size><width>64</width><height>64</height><depth>3</depth></size><object><name>dog</name><pose>Unspecified</pose><truncated>0</truncated><difficult>0</difficult><occluded>0</occluded><bndbox><xmin>20</xmin><xmax>30</xmax><ymin>30</ymin><ymax>40</ymax></bndbox></object></annotation>
1 change: 1 addition & 0 deletions train_annotations/image_3.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<annotation><filename>image_3.png</filename><path>image_3.png</path><source><database>example</database></source><size><width>64</width><height>64</height><depth>3</depth></size><object><name>cat</name><pose>Unspecified</pose><truncated>0</truncated><difficult>0</difficult><occluded>0</occluded><bndbox><xmin>10</xmin><xmax>15</xmax><ymin>20</ymin><ymax>45</ymax></bndbox></object></annotation>