image icon indicating copy to clipboard operation
image copied to clipboard

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

Open Leprechault opened this issue 4 years ago • 10 comments

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?

Leprechault avatar Apr 08 '20 14:04 Leprechault

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

jwijffels avatar Apr 08 '20 15:04 jwijffels

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)

Leprechault avatar Apr 08 '20 17:04 Leprechault

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 avatar Apr 08 '20 18:04 jwijffels

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?

Leprechault avatar Apr 08 '20 19:04 Leprechault

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 avatar Apr 08 '20 19:04 jwijffels

the version of darknet that this R package uses is referenced in commit at https://github.com/bnosac/image/commit/a0fb6b4b308784878029d6e1774c6297ffb5dc03

jwijffels avatar Apr 08 '20 19:04 jwijffels

Hey @leprechault,

If your issue is due to different YOLO versions found online and in this repo, please try my update: https://github.com/bnosac/image/pull/10

Good luck!

Am 08.04.2020 um 21:33 schrieb jwijffels [email protected]:  the version of darknet that this R package uses is referenced in commit at a0fb6b4

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

georoen avatar Apr 08 '20 20:04 georoen

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

Leprechault avatar Apr 08 '20 20:04 Leprechault

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)

emhedlin avatar May 13 '20 02:05 emhedlin

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 :(

Leprechault avatar May 18 '20 14:05 Leprechault