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

[image.darknet] output error: file.exists(model) is not TRUE #18

Open
Leprechault opened this issue Apr 8, 2020 · 10 comments
Open

[image.darknet] output error: file.exists(model) is not TRUE #18

Leprechault opened this issue Apr 8, 2020 · 10 comments

Comments

@Leprechault
Copy link

I've like to use the image_darknet_model() with my custom YOLOv3 model. For this, first I put my obj_100.weights file that represents the weights of my custom model create using darknet53.conv.74 inside the library directory image.darknet/models. After, I make the same with my obj.cfg in image.darknet/include/darknet/cfg directory and obj.names in image.darknet/include/darknet/data directory. Then, I try to use the image_darknet_model() function:

library(image.darknet)
yolo_v3_my_weights <- image_darknet_model(type = 'classify',
                                           model = "obj.cfg", weights = system.file(package="image.darknet", "models", "obj_100.weights"), 
labels = system.file(package="image.darknet", "include", "darknet", "data", "obj.names"))
Error in image_darknet_model(type = "classify", model = "obj.cfg", weights = system.file(package = "image.darknet",  : 
  file.exists(model) is not TRUE

But the I have the model in correct directory:

setwd("~/R/win-library/3.6/image.darknet/models")
dir()
[1] "obj_100.weights"       "tiny-yolo-voc.weights" "tiny.weights"

The file is OK and I don't have any problem with obj_100.weights file in the darknet in Python.

Please, any solution for this?

@jwijffels
Copy link
Contributor

It gives an error about your "obj.cfg" file, not about the weights. Just provide the full path to the "obj.cfg" file.

@Leprechault
Copy link
Author

Leprechault commented Apr 8, 2020

It gives an error about your "obj.cfg" file, not about the weights. Just provide the full path to the "obj.cfg" file.

Thanks @jwijffels works:

yolo_v3_my_weights <- image_darknet_model(type = 'classify',
model = "~/R/win-library/3.6/image.darknet/include/darknet/cfg/obj.cfg", weights = system.file(package="image.darknet", "models", "obj_100.weights"), 
labels = system.file(package="image.darknet", "include", "darknet", "data", "obj.names"))

But, when I try to apply image_darknet_detect function, doesn't work for both types, classify or detect.
For classify:

x <- image_darknet_detect(file = "C:/Users/fores/Dropbox/CNN4ants_Python/R_tests/test_im.png",                            object = yolo_v3_my_weights)
Error in image_darknet_detect(file = "C:/Users/fores/Dropbox/CNN4ants_Python/R_tests/test_im.png",  : 
  object$type == "detect" is not TRUE

For detect:

#Try detect
yolo_v3_my_weights <- image_darknet_model(type = 'detect',
model = "~/R/win-library/3.6/image.darknet/include/darknet/cfg/obj.cfg", weights = system.file(package="image.darknet", "models", "obj_100.weights"), 
labels = system.file(package="image.darknet", "include", "darknet", "data", "obj.names"))
#
x <- image_darknet_detect(file = "C:/Users/fores/Dropbox/CNN4ants_Python/R_tests/test_im.png", 
                          object = yolo_v3_my_weights,
                          threshold = 0.19)
#
Here R stops to work!!! R SESSION ABORTED
![image](https://user-images.githubusercontent.com/17205267/78816648-068f3c00-79a0-11ea-9c80-cbe9b4613298.png)

@jwijffels
Copy link
Contributor

What have you trained, a classification model or an object detection model? Which were your labels that you used for training, which version of darknet did you train the model upon?

@Leprechault
Copy link
Author

What have you trained, a classification model or an object detection model? Which were your labels that you used for training, which version of darknet did you train the model upon?

@jwijffels I try to use the image.darknet package only to make the detection of my custom lca object in new *jpg images. I already using darknet (https://github.com/pjreddie/darknet) in python, training my weights (./darknet detector train obj.data cfg/obj.cfg darknet53.conv.74) and I've to use the obj_100.weights file in image.darknet package for make the object detections image in R. Is possible?

@jwijffels
Copy link
Contributor

In theory this is possible, at least if you have trained it with the same version of darknet which I'm not sure this is the case - which might be the reason why it crashed when you did detect.

@jwijffels
Copy link
Contributor

the version of darknet that this R package uses is referenced in commit at a0fb6b4

@georoen
Copy link

georoen commented Apr 8, 2020 via email

@Leprechault
Copy link
Author

Thanks @georoen !!! I will try and give feedback here!!

@emhedlin
Copy link

Have you had any luck on your end @Leprechault ? I'm in precisely the same situation and was looking to use my python trained object detection model (yolov3) in R. I implemented the changes in @georoen 's pull request (#10), but the session still crashes. Was looking to confirm that it's not just a silly mistake on my end.

just in case it's useful for reference:

components <- image_darknet_model(type    = 'detect',
                                  model   = "full local path/yolov3.cfg", 
                                  weights = "full local path/yolov3_2000.weights", 
                                  labels  = "full local path/AN_obj.names")

d <- image_darknet_detect(file   = "full local path/image.jpg", 
                          object = components,
                          threshold = 0.19)

@Leprechault
Copy link
Author

Have you had any luck on your end @Leprechault ? I'm in precisely the same situation and was looking to use my python trained object detection model (yolov3) in R. I implemented the changes in @georoen 's pull request (#10), but the session still crashes. Was looking to confirm that it's not just a silly mistake on my end.

just in case it's useful for reference:

components <- image_darknet_model(type    = 'detect',
                                  model   = "full local path/yolov3.cfg", 
                                  weights = "full local path/yolov3_2000.weights", 
                                  labels  = "full local path/AN_obj.names")

d <- image_darknet_detect(file   = "full local path/image.jpg", 
                          object = components,
                          threshold = 0.19)

Bad news @emhedlin did not work wet. Unfortunately, the darknet support in python is a shame comparing with R web posts. I'll think to try another neural network framework :(

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

4 participants