Search code examples
pythongoogle-colaboratory

Google colab error to use files from google drive


So to use files from google drive in google colab I used this code:

from google.colab import drive
drive.mount('/content/gdrive')
!ln -s /content/gdrive/My\ Drive/ /mydrive
!ls /mydrive

Drive already mounted at /content/gdrive; to attempt to forcibly remount, call drive.mount("/content/gdrive", force_remount=True).
 app  'Colab Notebooks'   lixo  'My Drive'   pixellib   yolov3

Inside of pixellib I have the folder meat and the file pretraining.h5.

I installed this too:

!pip3 install pixellib

Until here, ok, but when I run this code:

import pixellib
from pixellib.custom_train import instance_custom_training

    train_maskrcnn = instance_custom_training()
    train_maskrcnn.modelConfig(network_backbone = "resnet101", num_classes= 2, batch_size = 4)
    train_maskrcnn.load_pretrained_model("/mydrive/pixellib/pretraining.h5")
    train_maskrcnn.load_dataset("/mydrive/pixellib/meat")
    train_maskrcnn.train_model(num_epochs = 20, augmentation=True,  path_trained_models = "/mydrive/pixellib/mask_rcnn_models")

the following error message appears:

Using resnet101 as network backbone For Mask R-CNN model
---------------------------------------------------------------------------
IsADirectoryError                         Traceback (most recent call last)
<ipython-input-44-8a3b66f50c89> in <module>()
      7 train_maskrcnn.modelConfig(network_backbone = "resnet101", num_classes= 2, batch_size = 4)
      8 train_maskrcnn.load_pretrained_model("/mydrive/pixellib/pretraining.h5")
----> 9 train_maskrcnn.load_dataset("/mydrive/pixellib/meat")
     10 train_maskrcnn.train_model(num_epochs = 20, augmentation=True,  path_trained_models = "/mydrive/pixellib/mask_rcnn_models")

7 frames
/usr/local/lib/python3.6/dist-packages/PIL/Image.py in open(fp, mode)
   2807 
   2808     if filename:
-> 2809         fp = builtins.open(filename, "rb")
   2810         exclusive_fp = True
   2811 

IsADirectoryError: [Errno 21] Is a directory: '/mydrive/pixellib/meat/train/78-3.jpg'

What kind of error is that? Something is wrong with my code?


Solution

  • If you have a json for every image in this directory (he said this in a comment), it seems likely to me that one of your json files has a .jpg ending. Either download both json and jpg and confirm that they are the correct file type, or you try to plot the image instead to see if it is an image.