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

boxes = torch.as_tensor(boxes).reshape(-1, 4) valueError #334

Closed
nprasad2021 opened this issue Jan 11, 2019 · 5 comments
Closed

boxes = torch.as_tensor(boxes).reshape(-1, 4) valueError #334

nprasad2021 opened this issue Jan 11, 2019 · 5 comments

Comments

@nprasad2021
Copy link

❓ Questions and Help

I am using a custom dataset w/ two classes coco-style with pre-trained detectron (R-50-FCN) weights as per issue #15 . I am running into the following errors (the first one I debugged, although not sure if I did it incorrectly).

  1. Since I transformed my dataset in a coco style, must it be named in such a way that coco is part of the name?
    I got the following error: RuntimeError: Dataset not available: head_train. I changed the name of the dataset to "cocohead_train" which fixed the error.

  2. I am running into the following error - stack trace below:

2019-01-11 22:53:47,537 maskrcnn_benchmark.trainer INFO: Start training
Traceback (most recent call last):
File "tools/train_net.py", line 171, in
main()
File "tools/train_net.py", line 164, in main
model = train(cfg, args.local_rank, args.distributed)
File "tools/train_net.py", line 73, in train
arguments,
File "/data/home/nprasad/Documents/github/maskrcnn-benchmark/maskrcnn_benchmark/engine/trainer.py", line 56, in do_train
for iteration, (images, targets, _) in enumerate(data_loader, start_iter):
File "/data/anaconda/envs/mask/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 468, in next
return self._process_next_batch(batch)
File "/data/anaconda/envs/mask/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 489, in _process_next_batch
raise batch.exc_type(batch.exc_msg)
ValueError: Traceback (most recent call last):
File "/data/anaconda/envs/mask/lib/python3.7/site-packages/torch/utils/data/_utils/worker.py", line 99, in _worker_loop
samples = collate_fn([dataset[i] for i in batch_indices])
File "/data/anaconda/envs/mask/lib/python3.7/site-packages/torch/utils/data/_utils/worker.py", line 99, in
samples = collate_fn([dataset[i] for i in batch_indices])
File "/data/anaconda/envs/mask/lib/python3.7/site-packages/torch/utils/data/dataset.py", line 81, in getitem
return self.datasets[dataset_idx][sample_idx]
File "/data/home/nprasad/Documents/github/maskrcnn-benchmark/maskrcnn_benchmark/data/datasets/coco.py", line 42, in getitem
boxes = torch.as_tensor(boxes).reshape(-1, 4) # guard against no boxes
ValueError: too many dimensions 'str'

@fmassa
Copy link
Contributor

fmassa commented Jan 14, 2019

Hi,

About your points:

1 - yes, for now we expect that coco-style datasets have COCO in the name


2 - can you add a print(boxes) just before the line that is raising the error, and set the number of worker threads to 0 to simplify identifying the issue?
_C.DATALOADER.NUM_WORKERS = 4

@nprasad2021
Copy link
Author

Thanks - the error was dataset related!

@fmassa
Copy link
Contributor

fmassa commented Jan 14, 2019

Cool, I'm closing the issue then, let me know if you find other problems.

@nprasad2021
Copy link
Author

My custom dataset does not have segmentation data - I just want to train a model for the object detection task. The defaults in the config set the mask to False, yet, an error still exists as the Coco dataset expects segmentation data. Should I simply comment out line 51 in coco.py such that the mask is not added to the annotation?

File "/data/anaconda/envs/mask/lib/python3.7/site-packages/torch/utils/data/dataset.py", line 81, in getitem
return self.datasets[dataset_idx][sample_idx]
File "/data/home/nprasad/Documents/github/maskrcnn-benchmark/maskrcnn_benchmark/data/datasets/coco.py", line 51, in getitem
masks = [obj["segmentation"] for obj in anno]
File "/data/home/nprasad/Documents/github/maskrcnn-benchmark/maskrcnn_benchmark/data/datasets/coco.py", line 51, in
masks = [obj["segmentation"] for obj in anno]
KeyError: 'segmentation'

@fmassa
Copy link
Contributor

fmassa commented Jan 14, 2019

Yes, if your dataset doesn't contain segmentation, you can just comment / remove

masks = [obj["segmentation"] for obj in anno]
masks = SegmentationMask(masks, img.size)
target.add_field("masks", masks)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants