Darknet: STB Reason: can't fopen/STB Reason: unknown image type Cannot load image - tried other solution

Created on 17 Mar 2019  路  11Comments  路  Source: pjreddie/darknet

I am getting the following error for some images (custom dataset) as a result of which the training stops.
(I am using /path/to/ as an abbreviation of my absolute path. All the files and images exist.)

Loading weights from ./darknet53.conv.74...Done!
Cannot load image "/path/to/Object_Detection/Ground/JPEGImages/Training/6/um_50_na_sunny_sony_0_384.jpg"
STB Reason: can't fopen
Cannot load image "/path/to/Object_Detection/Ground/JPEGImages/Training/6/um_50_na_sunny_sony_0_41.jpg"
STB Reason: unknown image type
Cannot load image "/path/to/Object_Detection/Ground/JPEGImages/Training/3/golf_40_na_cloudy_sony_0_273.jpg"
STB Reason: unknown image type

My images are present in the location too and their corresponding text files are in the following location:
/path/to/Object_Detection/Ground/labels/Training/...

The format of the folders are like Pascal VOC

here's a part of the makefile:
GPU=1
CUDNN=0
OPENCV=1
OPENMP=0
DEBUG=0

And here's my ground.data:

classes= 19
train  = /path/to/Object_Detection/ground_train.txt
valid  = /path/to/Object_Detection/ground_val.txt
names = /path/to/darknet/data/ground.names
backup = /path/to/darknet/backup/ground/

Here's the command I am using:

./darknet detector train /path/to/darknet/cfg/ground.data /path/to/darknet/cfg/yolov3-ground.cfg ./darknet53.conv.74 > /path/to/darknet/scripts/ground-train.log

Here's how my ground_train.txt (has all absolute path for images. only a portion of the entire file is shown) looks :

/path/to/Object_Detection/Ground/JPEGImages/Training/0/analog_50_180_sunny_sony_0_0.jpg
/path/to/Object_Detection/Ground/JPEGImages/Training/0/analog_50_180_sunny_sony_0_1.jpg
/path/to/Object_Detection/Ground/JPEGImages/Training/0/analog_50_180_sunny_sony_0_2.jpg
...

All the files exists and are valid. I am not sure what's wrong. It works for other files in the training dataset but only stops for these. I checked whether the images are of correct format, and they seem ok.

Here's the output after 14 epochs, my training stops after this:

14: 573.572327, 927.539124 avg, 0.000000 rate, 1636.650012 seconds, 896 images
Loaded: 0.000064 seconds
: 0.219096, Class: 0.386432, Obj: 0.530981, No Obj: 0.511523, .5R: 0.000000, .75R: 0.000000,  count: 2
Region 106 Avg IOU: 0.011220, Class: 0.282754, Obj: 0.311355, No Obj: 0.468680, .5R: 0.000000, .75R: 0.000000,  count: 1
Region 82 Avg IOU: 0.279148, Class: 0.148486, Obj: 0.629275, No Obj: 0.458073, .5R: 0.000000, .75R: 0.000000,  count: 1
Region 94 Avg IOU: 0.075961, Class: 0.271695, Obj: 0.082233, No Obj: 0.514065, .5R: 0.000000, .75R: 0.000000,  count: 2
Region 106 Avg IOU: 0.352088, Class: 0.543684, Obj: 0.793743, No Obj: 0.471246, .5R: 0.000000, .75R: 0.000000,  count: 1
Region 82 Avg IOU: 0.165622, Class: 0.815933, Obj: 0.489756, No Obj: 0.457557, .5R: 0.000000, .75R: 0.000000,  count: 1
Region 94 Avg IOU: 0.053709, Class: 0.664887, Obj: 0.541732, No Obj: 0.512764, .5R: 0.000000, .75R: 0.000000,  count: 2
Region 106 Avg IOU: 0.073817, Class: 0.247052, Obj: 0.413561, No Obj: 0.469873, .5R: 0.000000, .75R: 0.000000,  count: 1
14: 573.572327, 927.539124 avg, 0.000000 rate, 1636.650012 seconds, 896 images
Loaded: 0.000064 seconds

Most helpful comment

I'm also getting the same problem.

All 11 comments

I am getting the same issue Cannot load image "./darknet/dataset/z1.jpg" STB Reason: can't fopen @sbanerj2

I'm also getting the same problem.

I'm getting the same issue on Windows using the bash shell.

The same happens here on ubuntu 18.04. Now here's the funny part: after retrying 5-10 times while randomly changing the file name it suddenly works. Even when I use files that previously gave an error. And once it works it remains working without any error.

Now I'm not really a linux expert, but could it be that there is some sort of background process that takes some time to start?

For me the problem was compilation. I was compiling yolo with a wrong version of CUDA. Use the fork by alexeyab and make sure you have all the requirements. Make sure to update the makefile to

ifeq ($(GPU), 1)

COMMON+= -DGPU -I/usr/local/cuda/include/ -I/path/to/cudnn/7.0.5/cuda/include
CFLAGS+= -DGPU
ifeq ($(OS),Darwin) #MAC
LDFLAGS+= -L/usr/local/cuda/lib -lcuda -lcudart -lcublas -lcurand
else
LDFLAGS+= -L/path/to/cuda/ -lcuda -lcudart -lcublas -lcurand
endif
endif

ifeq ($(CUDNN), 1)
COMMON+= -DCUDNN
ifeq ($(OS),Darwin) #MAC
CFLAGS+= -DCUDNN -I/usr/local/cuda/include
LDFLAGS+= -L/usr/local/cuda/lib -lcudnn
else
CFLAGS+= -DCUDNN -I/opt/crc/c/cudnn/7.0.5/cuda/include
LDFLAGS+= -L/path/to/cudnn/<version>/cuda/lib64 -lcudnn
endif
endif

I am getting the same error. Did anybody solve it?

@Shruthi-Sampathkumar Use the fork, it worked for me.

Screen Shot 2019-11-25 at 3 32 26 PM

'/Users/yudiz/Downloads/darknet-master/build/darknet/x64/data/obj/000001.jpg'
It worked for me , issue was a extra 'space' between two new lines !!!

Use the strip() function in python to get rid of the trailing & leading new lines before feeding the image path for detection. The image paths in txt files contain extra new lines.

The same happens here on ubuntu 18.04. Now here's the funny part: after retrying 5-10 times while randomly changing the file name it suddenly works. Even when I use files that previously gave an error. And once it works it remains working without any error.

Now I'm not really a linux expert, but could it be that there is some sort of background process that takes some time to start?

hi, which file did you rename to please? I too am stuck with same issue on Mac terminal.

hi, you can use the python's imghdr to check the image Is it really jpg format

  1. example
import imghdr
print(imghdr.what("/path/to/Object_Detection/Ground/JPEGImages/Training/6/um_50_na_sunny_sony_0_384.jpg"))
# maybe print  **webp* ! not jpg ~
  1. now, write a sample filter script like this ~
import imghdr

def main():
    file_list = []
    with open("/path/to/Object_Detection/ground_train.txt") as f:
        for name in f.readlines():
            name = name.replace('\n','')
            try:
                img_type = name.split('.')[-1]
                if imghdr.what(name) in ['jpeg', img_type]:
                    print(name)
                    file_list.append(name)
            except FileNotFoundError:
                # print(name)
                continue
    with open("/path/to/Object_Detection/ground_train.txt", "w") as f:
        for name in file_list:
            f.write(name + '\n')

if __name__ == "__main__":
    main()
Was this page helpful?
0 / 5 - 0 ratings