#install.packages("devtools")
# devtools::install_github("bnosac/image", subdir = "image.darknet", build_vignettes = TRUE)Final Part3
Finally found a way to identify objects in a picture. The neural network to do this is called Yolo. Here is a blog post about how to use Yolo in R. Object detection in just 3 lines of R code using Tiny YOLO and the ggnot2 YouTube video Image Classification and Object Detection in R using just TWO lines of code!
# install.packages("image.darknet", repos = "https://bnosac.github.io/drat")# Load package
library(tibble)
library(image.darknet)
library(magick)Linking to ImageMagick 6.9.12.3
Enabled features: cairo, fontconfig, freetype, heic, lcms, pango, raw, rsvg, webp
Disabled features: fftw, ghostscript, x11
library(EBImage)Warning: package 'EBImage' was built under R version 4.2.3
img <- image_read("/Users/home/Documents/study/Master/STAT 654 - Deep Learning/11_Yolo/test1.jpeg")
a1 <- readImage("/Users/home/Documents/study/Master/STAT 654 - Deep Learning/11_Yolo/test1.jpeg")
display(a1)#Classify
# darknet_model <- image_darknet_model(type = "classify",
# model = "tiny.cfg",
# weights = system.file(package = "image.darknet", "models", "tiny.weights"),
# labels = system.file(package = "image.darknet", "include", "darknet", "data", "imagenet.shortnames.list"))
# yolo_results <- image_darknet_classify(file = "/Users/home/Documents/study/Master/STAT 654 - Deep Learning/11_Yolo/test1.jpeg",
# object = darknet_model)
#Detect
darknet_model <- image_darknet_model(type = "detect",
model = "tiny-yolo-voc.cfg",
weights = system.file(package = "image.darknet", "models", "tiny-yolo-voc.weights"),
labels = system.file(package = "image.darknet", "include", "darknet", "data", "voc.names"))
image_darknet_detect(file = "/Users/home/Documents/study/Master/STAT 654 - Deep Learning/11_Yolo/test1.jpeg",
object = darknet_model)pred <- readImage("/Users/home/Documents/study/Master/STAT 654 - Deep Learning/11_Yolo/predictions.png")
display(pred)