Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot load image, STB Reason: expected marker #312

Open
lengly opened this issue Nov 15, 2017 · 13 comments
Open

Cannot load image, STB Reason: expected marker #312

lengly opened this issue Nov 15, 2017 · 13 comments

Comments

@lengly
Copy link

lengly commented Nov 15, 2017

When I try to train it on COCO:

./darknet detector train cfg/coco.data cfg/yolo.cfg weights/darknet19_448.conv.23 -gpus 0,1,2,3

I see such error

Region Avg IOU: 0.495555, Class: 0.534914, Obj: 0.116917, No Obj: 0.007393, Avg Recall: 0.468750,  count: 32
Region Avg IOU: 0.268316, Class: 0.294134, Obj: 0.117317, No Obj: 0.008529, Avg Recall: 0.222222,  count: 36
Region Avg IOU: 0.384779, Class: 0.296443, Obj: 0.101438, No Obj: 0.007914, Avg Recall: 0.343750,  count: 32
Syncing... Cannot load image "/home/walle/lyd/datasets/COCO/coco/images/train2014/COCO_train2014_000000167126.jpg"
STB Reason: expected marker
Done!
2544: 32.557770, 34.544533 avg, 0.004000 rate, 3.863461 seconds, 325632 images
Loaded: 0.000039 seconds

This error happend randomly, anyone knows how to solve it?

@RichardYinguo
Copy link

Have you solved the problem? I meet the same

@lengly
Copy link
Author

lengly commented Jan 2, 2018

@RichardYinguo Something wrong with that image, please delete it in the list. don't know why...

@RichardYinguo
Copy link

thanks

@jeremy-rutman
Copy link

These appear to be images that got truncated. opencv loads them fine with original dimensions, (so a check in parse.py won't prevent the problem) but the darknet code dies on them.

I found 2 examples and uploaded to
https://ibb.co/njvyf8
https://ibb.co/fQ3Uno

@mhaghighat
Copy link

mhaghighat commented Aug 2, 2018

I faced the same issue. Is the COCO_train2014_000000167126.jpg the only image that causes this error or are there others down the road? If this is the only one, we can simply remove it from the trainvalno5k.txt.

UPDATE:
Yes, it is the only damaged image. You can simply remove it from the list.

@jeremy-rutman
Copy link

any truncated image will do this due to the c code used for loading the image. You can add a check to the code eg. a try/catch, or hope there are no more truncated images in your dataset

@leicao-me
Copy link

leicao-me commented Sep 29, 2018

If you take a look at the image that can’t be loaded - COCO_train2014_000000167126.jpg, you will see it’s damaged.

Solution:
Download the undamaged version of the image and replace the damaged
https://msvocds.blob.core.windows.net/images/262993_z.jpg

You are welcome. :)

References:
Damaged Image:
https://blog.csdn.net/chengyq116/article/details/80258821
Replacement:
karpathy/neuraltalk2#4

@usb1508
Copy link

usb1508 commented Jun 27, 2019

Did someone solve the problem, in which the solution doesn't involve redownloading the damaged image?
Because I initially used the same images to train, and it worked fine. But the next time I reset the session of VM, this particular error pops up.
Is there some way this could be avoided as currently, I need to unzip the dataset every time I use a new session.

@jeremy-rutman
Copy link

jeremy-rutman commented Jul 1, 2019 via email

@chenjiahe01
Copy link

chenjiahe01 commented Jul 23, 2019

I've work on it all day.Finally I make it!!
Find "darknet/src/image.h" and open it in editor.
change the function
image load_image_stb(char *filename, int channels)
{
int w, h, c;
unsigned char *data = stbi_load(filename, &w, &h, &c, channels);
if (!data) {
fprintf("shit!")//stderr, "Cannot load image \"%s\"\nSTB Reason: %s\n", filename, stbi_failure_reason());
exit(0);
}
if(channels) c = channels;
int i,j,k;
image im = make_image(w, h, c);
for(k = 0; k < c; ++k){
for(j = 0; j < h; ++j){
for(i = 0; i < w; ++i){
int dst_index = i + w*j + w*h*k;
int src_index = k + c*i + c*w*j;
im.data[dst_index] = (float)data[src_index]/255.;
}
}
}
free(data);
return im;
}
to:
image load_image_stb(char *filename, int channels)
{
int w, h, c;
unsigned char *data = stbi_load(filename, &w, &h, &c, channels);
if (!data) {
//fprintf("shit!")//stderr, "Cannot load image \"%s\"\nSTB Reason: %s\n", filename, stbi_failure_reason());
//exit(0);
image i;
return i;
}
if(channels) c = channels;
int i,j,k;
image im = make_image(w, h, c);
for(k = 0; k < c; ++k){
for(j = 0; j < h; ++j){
for(i = 0; i < w; ++i){
int dst_index = i + w*j + w*h*k;
int src_index = k + c*i + c*w*j;
im.data[dst_index] = (float)data[src_index]/255.;
}
}
}
free(data);
return im;
}
Now, if the image to be loaded is truncated. The load_image program will return an empty image instead of exit.
Then we can useif(im.w==0) to skip the image automatically or what.

@dmitrygashnikov
Copy link

Find "darknet/src/image.h" and open it in editor.
change the function

Thx for solution, will try it later today. One correction:
not find those class in "darknet/src/image.h" by myself.
In my version its located in "darknet/src/image.c"
And reminder for thouse, who will try this solution - do not foorget to rebuild project after making changes.

P.S. Sorry for my english

@dranaivo
Copy link

dranaivo commented Oct 6, 2020

I've work on it all day.Finally I make it!!
Find "darknet/src/image.h" and open it in editor.
change the function
image load_image_stb(char *filename, int channels)
{
int w, h, c;
unsigned char *data = stbi_load(filename, &w, &h, &c, channels);
if (!data) {
fprintf("shit!")//stderr, "Cannot load image \"%s\"\nSTB Reason: %s\n", filename, stbi_failure_reason());
exit(0);
}
if(channels) c = channels;
int i,j,k;
image im = make_image(w, h, c);
for(k = 0; k < c; ++k){
for(j = 0; j < h; ++j){
for(i = 0; i < w; ++i){
int dst_index = i + w*j + w*h*k;
int src_index = k + c*i + c*w*j;
im.data[dst_index] = (float)data[src_index]/255.;
}
}
}
free(data);
return im;
}
to:
image load_image_stb(char *filename, int channels)
{
int w, h, c;
unsigned char *data = stbi_load(filename, &w, &h, &c, channels);
if (!data) {
//fprintf("shit!")//stderr, "Cannot load image \"%s\"\nSTB Reason: %s\n", filename, stbi_failure_reason());
//exit(0);
image i;
return i;
}
if(channels) c = channels;
int i,j,k;
image im = make_image(w, h, c);
for(k = 0; k < c; ++k){
for(j = 0; j < h; ++j){
for(i = 0; i < w; ++i){
int dst_index = i + w*j + w*h*k;
int src_index = k + c*i + c*w*j;
im.data[dst_index] = (float)data[src_index]/255.;
}
}
}
free(data);
return im;
}
Now, if the image to be loaded is truncated. The load_image program will return an empty image instead of exit.
Then we can useif(im.w==0) to skip the image automatically or what.

@chenjiahe01 As I am not really good with C, can you elaborate a bit on the use of the condition if (im.w==0) to skip the image, namely where in the file can you use it and if possible an example of snippet. Thank you!

@HtR212
Copy link

HtR212 commented Aug 5, 2022

@dranaivo You can check if (im.w==0) in the function test_detector inside "darknet/examples/detector.c". You also have to modify the load_image function inside "darknet/src/image.c" to make it return out before the if statement to avoid the resizing part.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants