OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

JSON file not found when using custom dataset in detectron2

  • Thread starter Thread starter Laura Rabadan Camacho
  • Start date Start date
L

Laura Rabadan Camacho

Guest
I am trying to train a model in detectron2 with a custom dataset I annotated myself in CVAT. I downloaded the annotation in COCO JSON format. However, when following the tutorial from detectron2 to upload custom COCO format datasets I get the error:

Code:
FileNotFoundError: [Errno 2] No such file or directory: './content/resectionline/train/instances.json'

This is the last code I tried in Google Colab:

Code:
from detectron2.data.datasets import register_coco_instances
register_coco_instances("resectionline_train", {}, "instances.json", "content/resectionline/train")
register_coco_instances("resectionline_val", {}, "instances.json", "content/resectionline/val")

from detectron2.data.datasets import register_coco_instances
register_coco_instances("resectionline", {}, "./content/resectionline/train/instances.json", "./content/resectionline/train/")

dataset_dicts = DatasetCatalog.get("resectionline")

Code:
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-34-4aea893e4172> in <cell line: 1>()
----> 1 dataset_dicts = DatasetCatalog.get("resectionline")

3 frames
/usr/local/lib/python3.10/dist-packages/pycocotools/coco.py in __init__(self, annotation_file)
     79             print('loading annotations into memory...')
     80             tic = time.time()
---> 81             with open(annotation_file, 'r') as f:
     82                 dataset = json.load(f)
     83             assert type(dataset)==dict, 'annotation file format {} not supported'.format(type(dataset))

FileNotFoundError: [Errno 2] No such file or directory: './content/resectionline/train/instances.json'

I tried to do it with an example dataset I found online and the same code worked. So I know it is a problem with my JSON file.

I downloaded it in COCO format. I did the folder structure the same as them. I also tried this: Python FileNotFoundError: [Errno 2] No such file or directory:

Nothing worked.

Btw, the path the error shows is correct and the file is there.
<p>I am trying to train a model in detectron2 with a custom dataset I annotated myself in CVAT.
I downloaded the annotation in COCO JSON format. However, when following the tutorial from detectron2 to upload custom COCO format datasets I get the error:</p>
<pre><code>FileNotFoundError: [Errno 2] No such file or directory: './content/resectionline/train/instances.json'

</code></pre>
<p>This is the last code I tried in Google Colab:</p>
<pre><code>from detectron2.data.datasets import register_coco_instances
register_coco_instances("resectionline_train", {}, "instances.json", "content/resectionline/train")
register_coco_instances("resectionline_val", {}, "instances.json", "content/resectionline/val")

from detectron2.data.datasets import register_coco_instances
register_coco_instances("resectionline", {}, "./content/resectionline/train/instances.json", "./content/resectionline/train/")

dataset_dicts = DatasetCatalog.get("resectionline")
</code></pre>
<pre><code>FileNotFoundError Traceback (most recent call last)
<ipython-input-34-4aea893e4172> in <cell line: 1>()
----> 1 dataset_dicts = DatasetCatalog.get("resectionline")

3 frames
/usr/local/lib/python3.10/dist-packages/pycocotools/coco.py in __init__(self, annotation_file)
79 print('loading annotations into memory...')
80 tic = time.time()
---> 81 with open(annotation_file, 'r') as f:
82 dataset = json.load(f)
83 assert type(dataset)==dict, 'annotation file format {} not supported'.format(type(dataset))

FileNotFoundError: [Errno 2] No such file or directory: './content/resectionline/train/instances.json'

</code></pre>
<p>I tried to do it with an example dataset I found online and the same code worked. So I know it is a problem with my JSON file.</p>
<p>I downloaded it in COCO format.
I did the folder structure the same as them.
I also tried this: <a href="https://stackoverflow.com/questions...tfounderror-errno-2-no-such-file-or-directory">Python FileNotFoundError: [Errno 2] No such file or directory:</a></p>
<p>Nothing worked.</p>
<p>Btw, the path the error shows is correct and the file is there.</p>
 

Latest posts

Top