bnosac / image

Computer Vision and Image Recognition algorithms for R users
274 stars 65 forks source link

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

Open Leprechault opened 4 years ago

Leprechault commented 4 years ago

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 commented 4 years ago

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

Leprechault commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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

georoen commented 4 years ago

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 notifications@github.com:  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.

Leprechault commented 4 years ago

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

emhedlin commented 4 years ago

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 commented 4 years ago

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