Skip to content
Advertisement

Couldn’t open file yolov3_custom_last.weights when trying to run darknet detection

I’ve been trying to use YOLO (v3) to implement and train an object detection of Tank with OpenImage dataset. I have tried to get help from this tutorial and my code pretty much looks like it. Also I’m using Google Colab and Google Drive services. everything is going fine through my program. But I hit an error at the final step when I’m running the darknet to train detection.

!./darknet detector train "data/obj.data" cfg/yolov3_custom.cfg "darknet53.conv.74" -dont_show

after 100 iterations, when it’s trying to save the progress in the backup folder I’ve addressed in obj.data file, I get the following error:

Saving weights to /content/drive/MyDrive/YOLOv3/backup/yolov3_custom_last.weights
Couldn't open file: /content/drive/MyDrive/YOLOv3/backup/yolov3_custom_last.weights

at first, I thought I made a mistake in using the address; So, I tried checking the address by using ls command

!ls /content/drive/MyDrive/YOLOv3/backup/

and the result was an empty folder (However, not an error meaning I’ve written the address correctly and that it is accessable in my google drive).

Here are contents of data.object file:

classes = 1
train = data/train.txt
valid = data/test.txt
names = data/obj.names
backup = /content/drive/My Drive/YOLOv3/backup

also I’ve made required changes in config file so I don’t think that the problem is about that. But just to make sure here are the changes I’ve made in my yolov3.cfg file:

  1. Fist of all we will comment lines 3 and 4 (batch, subdivisions) to unset testing mode
  2. We will uncomment lines 6 and 7(batch, subdivisions) to set to training mode
  3. We change our max_batches value to 2000 * number_of_classes (if there’s one class like our case, set to 4000)
  4. We change our step tuple-like values to 80%, 90% value of our max_baches value. In this case it will be 3200, 3600.
  5. For all YOLO layers and convoloutional layers before them, changed the classes value to number of classes, In this case 1, and change the value of filters according to following formula(In this case, 18)

Formula for conv layers filters value: (number_of_classes + 5)*3

I searched the error and found this issue on Github. However, I tried the following methods recommended there and the problem is still the same:

  1. Removing and recreating the backup folder
  2. Tried to adding the line backup = backup in my yolo.data file in folder .cfg but there was no such file in cfg folder.
  3. Creating an empty yolov3_custom_last.weights in backup folder

The other solutions mentioned in this issue was about when you are running YOLO on your PC and not google Colab. Also, here my tree structure of the folder YOLOv3 which is stored in my Google Drive My Drive(main folder).

YOLOv3
        darknet53.conv.74
        obj.data
        obj.names
        Tank.zip
        yolov3.weights
        yolov3_custom.cfg
        yolov3_custom1.cfg.txt

So, I’m kinda stuck and I have no idea what could fix this. I’d appreciate some help.

Advertisement

Answer

I have solved the problem with changing the local drive address with ln command. The problem wasn’t from my code rather from the way way yolov3 developers were handling space in directory addresses! Apparently as much as I figured in their docs, they are not handling space in directory quite well. So I created a virtual address which does not have space like My Drive has. P.S: As you know My Drive folder is already there in your google drive so you can’t actually rename it. Here is the code you can use to achieve this:

!ln -s /content/drive/My Drive/ /mydrive

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement