ayoolaolafenwa / PixelLib

Visit PixelLib's official documentation https://pixellib.readthedocs.io/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

IsADirectoryError when loading dataset

p4bloR opened this issue · comments

Hi, I'm currently trying to follow this tutorial: https://towardsdatascience.com/custom-instance-segmentation-training-with-7-lines-of-code-ff340851e99b
The problem comes when I try to load de dataset in this line of code:

vis_img.load_dataset("Nature")

I get the following error:

IsADirectoryError: [Errno 21] Is a directory: '/content/drive/MyDrive/Test_2/Nature/train.json'

I tried making my own dataset with labelme and the error persists. I'm currently running this on a google colab machine with a conda enviroment running.
I did some research and it seems this error comes from trying to pass a directory when python expects a file, but I don't understand what I should do differently, I'm literally copying code from a tutorial. Maybe I should try with older versions of the same libraries?
Thanks in advance.

I have same problem too.

Reading other threads it seemed that this problem is caused by an update in the labelme2coco library. So this problem can be fixed by using older libraries.

I copied this code from another issue and it solved it for me:

!pip3 uninstall tensorflow
!pip3 install tensorflow==2.4.1
!pip3 install tensorflow--gpu
!pip3 install imgaug
!pip install pixellib==0.5.2
!pip install labelme2coco==0.1.2

EDIT: This worked for me on google colab.

Thanks p4bloR. In my case it works:
pixellib==0.7.0
labelme2coco==0.1.2
but only on colab. For my Windows10 and on Kaggle also don't work.
Do somebody now how to do prediction with instance_custom_training? Some code example...

Thanks p4bloR. In my case it works: pixellib==0.7.0 labelme2coco==0.1.2 but only on colab. For my Windows10 and on Kaggle also don't work. Do somebody now how to do prediction with instance_custom_training? Some code example...

You're welcome, thanks for sharing what worked for you.

About the instance_custom_training thing, I think you should open a new issue to ask about it. This issue is about receiving a IsADirectoryError error when trying to load a dataset. I think it's important to keep issues like this organized so people in the future can quickly search and find answers.

I'm having the same problem. It's a csv and I have no problems in colab but it's giving me a directory error.

Hi all, I am still incapable of making it work. I am using Colab with this environment:

!pip3 uninstall tensorflow !pip3 install tensorflow==2.4.3 !pip3 install tensorflow--gpu !pip3 install imgaug !pip install pixellib==0.5.2 !pip install labelme2coco==0.1.2

When I run this:

import pixellib from pixellib.custom_train import instance_custom_training train_maskrcnn = instance_custom_training() train_maskrcnn.modelConfig(network_backbone = "resnet101", num_classes= 1, batch_size = 2) train_maskrcnn.load_pretrained_model("/content/drive/My Drive/Colab Notebooks/mask_rcnn_coco.h5") train_maskrcnn.load_dataset("/content/drive/My Drive/Colab Notebooks/Cars") train_maskrcnn.train_model(num_epochs = 300, augmentation=True, path_trained_models = "mask_rcnn_models")

I get this

IsADirectoryError: [Errno 21] Is a directory: '/content/drive/My Drive/Colab Notebooks/Cars/train.json'

It seems that instead of creating both train and test jsons in their respective directory, it is creating just the training one and providing the path of a folder instead of the json object which is inside that folder and named dataset.json.

Could anyone help?

Thanks in advance.

Hi all, I am still incapable of making it work. I am using Colab with this environment:

!pip3 uninstall tensorflow !pip3 install tensorflow==2.4.3 !pip3 install tensorflow--gpu !pip3 install imgaug !pip install pixellib==0.5.2 !pip install labelme2coco==0.1.2

When I run this:

import pixellib from pixellib.custom_train import instance_custom_training train_maskrcnn = instance_custom_training() train_maskrcnn.modelConfig(network_backbone = "resnet101", num_classes= 1, batch_size = 2) train_maskrcnn.load_pretrained_model("/content/drive/My Drive/Colab Notebooks/mask_rcnn_coco.h5") train_maskrcnn.load_dataset("/content/drive/My Drive/Colab Notebooks/Cars") train_maskrcnn.train_model(num_epochs = 300, augmentation=True, path_trained_models = "mask_rcnn_models")

I get this

IsADirectoryError: [Errno 21] Is a directory: '/content/drive/My Drive/Colab Notebooks/Cars/train.json'

It seems that instead of creating both train and test jsons in their respective directory, it is creating just the training one and providing the path of a folder instead of the json object which is inside that folder and named dataset.json.

Could anyone help?

Thanks in advance.

Same here does somebody has a solution?

!pip3 uninstall tensorflow
!pip3 install tensorflow==2.4.1
!pip3 install tensorflow--gpu
!pip3 install imgaug
!pip install pixellib==0.5.2
!pip install labelme2coco==0.1.0

worked for me.

The directory error is caused by PixelLib/pixellib/custom_train/init.py /, line 46, labelme2coco.convert(labelme_folder1, save_json_path1).

Downgrading the labelme2coco library solves the directory error.

I am experiencing this issue myself too and, I would rather not downgrade the version of the libraries. Is this issue being troubleshooted? The issue seems to be pretty much understood. The new labelme2coco is generating a dataset.json file inside a subfolder that on previous version, that same folder name used to be the json file itself. Seems a few lines of code need to be added in PixelLib to set the labelme2coco destination path for the json file. Any date when this issue will be fixed? I will really appreciate! :)

I agree with @ezcsdeveloper , I would rather not downgrade too.
I still have this issue in this configuration :

pixellib==0.7.1
labelme2coco==0.2.4
tensorflow==2.4.1 gpu_py39h8236f22_0
tensorflow-base==2.4.1 gpu_py39h29c2da4_0
tensorflow-estimator==2.6.0 pyh7b7c402_0
tensorflow-gpu==2.4.1 h30adc30_0

Python 3.9.16

Here is my Traceback :

Traceback (most recent call last):
  File "/home/pixellib-webcam/main2.py", line 13, in <module>
    vis_img.load_dataset("mydatasetfolder")
  File "/home/anaconda3/envs/tf-gpu/lib/python3.9/site-packages/pixellib/custom_train/__init__.py", line 68, in load_dataset
    self.dataset_train.load_data(save_json_path1, labelme_folder1)
  File "/home/anaconda3/envs/tf-gpu/lib/python3.9/site-packages/pixellib/custom_train/__init__.py", line 175, in load_data
    json_file = open(annotation_json)
IsADirectoryError: [Errno 21] Is a directory: '/home/pixellib-webcam/mydatasetfolder/train.json'

Basically, you have to downgrade labelme2coco.

Run the following command:

!pip install pixellib==0.5.2
!pip install labelme2coco==0.1.0

After this, click to "Restart runtime", delete the directory train.json running rm-rf path-to-/train.json and try again.