How to get object detection dataset with multiple bounding boxes per image to be indexable with PyTorch __getitem__ method?
up vote
0
down vote
favorite
I'm trying to override the __getitem__
method in the PyTorch Dataset abstract class for an object detection task where the dataset consists of multiple images, each of which has multiple bounding boxes.
https://pytorch.org/tutorials/beginner/data_loading_tutorial.html
The bounding boxes are defined by 5 parameters: the upper-left coordinate of the rectangle, the lower right coordinate of the rectangle, and the class label annotation for the object detected inside the bounding box.
So: x1, y1, x2, y2, class_label
The PyTorch __getitem__
method is supposed to return a single (image, set_of_bounding_box_and_annotations)
when called with an index of integer type. So __getitem__(17)
would return the 17th image with the set of all bounding-boxes and labels.
The format of the data is a dictionary of lists, each of which consists of a dictionary.
Ex:
my_dict =
{img_1.png: [x1: 0, y1: 0, x2: 10, y2: 20, label: 'dog', x1: 30, y1: 40, x2: 50, y2: 60, label: 'cat', ...],
img_2.png: [x1: 84, y1: 27, x2: 95, y2: 43, label: 'bird', x1: 91, y1: 91, x2: 102, y2: 110, label: 'alligator', ...],
...
So PyTorch requires the __getitem__
method to return an image,box-set sample when passing it the index of the data.
Problem is a dictionary has no inherent order in Python, so you can't just call my_dict[0]
. Seems like an OrderedDict
would work here, but we want the value of the key-value pair to be the set/list of boundingbox/label dictionaries.
How to get the data into an indexable format that the __getitem__
method can return a sample (image, bbox_and_labels)
?
python dictionary pytorch
add a comment |
up vote
0
down vote
favorite
I'm trying to override the __getitem__
method in the PyTorch Dataset abstract class for an object detection task where the dataset consists of multiple images, each of which has multiple bounding boxes.
https://pytorch.org/tutorials/beginner/data_loading_tutorial.html
The bounding boxes are defined by 5 parameters: the upper-left coordinate of the rectangle, the lower right coordinate of the rectangle, and the class label annotation for the object detected inside the bounding box.
So: x1, y1, x2, y2, class_label
The PyTorch __getitem__
method is supposed to return a single (image, set_of_bounding_box_and_annotations)
when called with an index of integer type. So __getitem__(17)
would return the 17th image with the set of all bounding-boxes and labels.
The format of the data is a dictionary of lists, each of which consists of a dictionary.
Ex:
my_dict =
{img_1.png: [x1: 0, y1: 0, x2: 10, y2: 20, label: 'dog', x1: 30, y1: 40, x2: 50, y2: 60, label: 'cat', ...],
img_2.png: [x1: 84, y1: 27, x2: 95, y2: 43, label: 'bird', x1: 91, y1: 91, x2: 102, y2: 110, label: 'alligator', ...],
...
So PyTorch requires the __getitem__
method to return an image,box-set sample when passing it the index of the data.
Problem is a dictionary has no inherent order in Python, so you can't just call my_dict[0]
. Seems like an OrderedDict
would work here, but we want the value of the key-value pair to be the set/list of boundingbox/label dictionaries.
How to get the data into an indexable format that the __getitem__
method can return a sample (image, bbox_and_labels)
?
python dictionary pytorch
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm trying to override the __getitem__
method in the PyTorch Dataset abstract class for an object detection task where the dataset consists of multiple images, each of which has multiple bounding boxes.
https://pytorch.org/tutorials/beginner/data_loading_tutorial.html
The bounding boxes are defined by 5 parameters: the upper-left coordinate of the rectangle, the lower right coordinate of the rectangle, and the class label annotation for the object detected inside the bounding box.
So: x1, y1, x2, y2, class_label
The PyTorch __getitem__
method is supposed to return a single (image, set_of_bounding_box_and_annotations)
when called with an index of integer type. So __getitem__(17)
would return the 17th image with the set of all bounding-boxes and labels.
The format of the data is a dictionary of lists, each of which consists of a dictionary.
Ex:
my_dict =
{img_1.png: [x1: 0, y1: 0, x2: 10, y2: 20, label: 'dog', x1: 30, y1: 40, x2: 50, y2: 60, label: 'cat', ...],
img_2.png: [x1: 84, y1: 27, x2: 95, y2: 43, label: 'bird', x1: 91, y1: 91, x2: 102, y2: 110, label: 'alligator', ...],
...
So PyTorch requires the __getitem__
method to return an image,box-set sample when passing it the index of the data.
Problem is a dictionary has no inherent order in Python, so you can't just call my_dict[0]
. Seems like an OrderedDict
would work here, but we want the value of the key-value pair to be the set/list of boundingbox/label dictionaries.
How to get the data into an indexable format that the __getitem__
method can return a sample (image, bbox_and_labels)
?
python dictionary pytorch
I'm trying to override the __getitem__
method in the PyTorch Dataset abstract class for an object detection task where the dataset consists of multiple images, each of which has multiple bounding boxes.
https://pytorch.org/tutorials/beginner/data_loading_tutorial.html
The bounding boxes are defined by 5 parameters: the upper-left coordinate of the rectangle, the lower right coordinate of the rectangle, and the class label annotation for the object detected inside the bounding box.
So: x1, y1, x2, y2, class_label
The PyTorch __getitem__
method is supposed to return a single (image, set_of_bounding_box_and_annotations)
when called with an index of integer type. So __getitem__(17)
would return the 17th image with the set of all bounding-boxes and labels.
The format of the data is a dictionary of lists, each of which consists of a dictionary.
Ex:
my_dict =
{img_1.png: [x1: 0, y1: 0, x2: 10, y2: 20, label: 'dog', x1: 30, y1: 40, x2: 50, y2: 60, label: 'cat', ...],
img_2.png: [x1: 84, y1: 27, x2: 95, y2: 43, label: 'bird', x1: 91, y1: 91, x2: 102, y2: 110, label: 'alligator', ...],
...
So PyTorch requires the __getitem__
method to return an image,box-set sample when passing it the index of the data.
Problem is a dictionary has no inherent order in Python, so you can't just call my_dict[0]
. Seems like an OrderedDict
would work here, but we want the value of the key-value pair to be the set/list of boundingbox/label dictionaries.
How to get the data into an indexable format that the __getitem__
method can return a sample (image, bbox_and_labels)
?
python dictionary pytorch
python dictionary pytorch
edited Nov 11 at 13:27
blue-phoenox
3,04471438
3,04471438
asked Nov 10 at 19:22
JohnnyDenim
273
273
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242588%2fhow-to-get-object-detection-dataset-with-multiple-bounding-boxes-per-image-to-be%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown