Skip to content

Commit

Permalink
Better renders (#14)
Browse files Browse the repository at this point in the history
* trying other rectangles

* example renders on readme

* image sizes

* Update README.md

* add cars

* Update README.md
  • Loading branch information
IanButterworth committed Sep 24, 2019
2 parents 36ff54d + 472cb5c commit 336773e
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .drone.yml
Expand Up @@ -7,7 +7,7 @@ platform:

steps:
- name: build
image: julia:1.3
image: julia:1.3.0-rc2
commands:
- uname -a
- julia --project=. -e 'using Pkg; Pkg.build(); Pkg.test(coverage=true)'
Expand All @@ -23,7 +23,7 @@ platform:

steps:
- name: build
image: julia:1.3
image: julia:1.3.0-rc2
commands:
- uname -a
- julia --project=. -e 'using Pkg; Pkg.build(); Pkg.test(coverage=true)'
Expand Down
11 changes: 8 additions & 3 deletions README.md
Expand Up @@ -4,7 +4,12 @@ Currently only supports loading [YOLOv2-tiny](https://github.com/pjreddie/darkne

The majority of this is made possible by Yavuz Bakman's great work in https://github.com/Ybakman/YoloV2

**Docs**
<p float="left">
<img src="examples/boat.png" alt="drawing" width="200"/>
<img src="examples/bikes.png" alt="bikes" width="200"/>
<img src="examples/cowcat.png" alt="cowcat" width="200"/>
<img src="examples/cars.png" alt="cars" width="200"/>
</p>

See below for examples or ask questions on [![Join the julia slack](https://img.shields.io/badge/slack-%23machine--learning-yellow)](https://slackinvite.julialang.org)

Expand Down Expand Up @@ -52,11 +57,11 @@ res = model(vocloaded.imstack_mat);
predictions = YOLO.postprocess(res, settings, conf_thresh = 0.3, iou_thresh = 0.3)
```

### Testing a single custom image
### Testing a single custom image
To pass an image through, the image needs to be loaded, and scaled to the appropriate input size.
For YOLOv2-tiny that would be `(w, h, color_channels, minibatch_size) == (416, 416, 3, 1)`.

`loadResizePadImageToFit` can be used to load, resize & pad the image, while maintaining aspect ratio and anti-aliasing during the resize process.
`loadResizePadImageToFit` can be used to load, resize & pad the image, while maintaining aspect ratio and anti-aliasing during the resize process.
```julia
using YOLO
## Load once
Expand Down
Binary file added examples/bikes.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/boat.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/cars.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/cowcat.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 16 additions & 5 deletions src/makierendering.jl
Expand Up @@ -13,16 +13,27 @@ function renderResult(img::Array{Float32}, predictions::Vector{YOLO.PredictLabel
Makie.rotate!(scene, -0.5pi)

for p in predictions
alpha = clamp(p.conf,0.5,1.0)
col = cols[p.class]
rect = [p.bbox.y*img_h, p.bbox.x*img_w, p.bbox.h*img_h, p.bbox.w*img_w]
Makie.poly!(scene, [Rectangle{Float32}(rect...)], color=RGBA(red(col),blue(col),green(col),clamp(p.conf*1.3,0.2,0.6)))
pcol = RGBA(red(col),blue(col),green(col),alpha)
x = p.bbox.x*img_w
y = p.bbox.y*img_h
w = p.bbox.w*img_w
h = p.bbox.h*img_h
points = [
Point(y,x+w) => Point(y+h,x+w);
Point(y,x) => Point(y+h,x);
Point(y+h,x+w) => Point(y+h,x);
Point(y,x+w) => Point(y,x);
]
Makie.linesegments!(points, linewidth = 8, color=pcol)
name = get(settings.numsdic,p.class,"")
conf_rounded = round(p.conf, digits=2)
Makie.text!(scene, "$name\n$(conf_rounded)",
position = (rect[1], rect[2]),
position = (y+3, x+3),
align = (:left, :top),
colo = :black,
textsize = 6,
color = pcol,
textsize = 8,
font = "Dejavu Sans"
)
end
Expand Down

0 comments on commit 336773e

Please sign in to comment.