---
title: "Yolo Example"
author: "Prof. Eric A. Suess"
format: html
---

From [ggnot2 Youtube](https://www.youtube.com/@ggnot2) [Image Classification and Object Detection in R using just TWO lines of code!](https://www.youtube.com/watch?v=ALttRR6kseg)

```{r}
#| echo: false
install.packages("image.darknet", repos = "https://bnosac.github.io/drat")
```

```{r}
# Load package
library(image.darknet)
```

```{r}
# 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"))
image_darknet_classify(file = "Beagle.jpg",
                       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 = "Beagle.jpg",
                     object = darknet_model)
```

