Git Product home page Git Product logo

darknet.jl's Introduction

Darknet.jl

Run tests Build Status Build status Build Status Codecov

Wrapper for https://github.com/AlexeyAB/darknet based on pre-build binaries.

Current support:

Platforms:
- i686-linux-gnu
- x86_64-linux-gnu
- aarch64-linux-gnu
- armv7l-linux-gnueabihf
- powerpc64le-linux-gnu
- i686-linux-musl
- x86_64-linux-musl
- aarch64-linux-musl
- armv7l-linux-musleabihf
- x86_64-apple-darwin14
- x86_64-unknown-freebsd11.1
- i686-w64-mingw32
- x86_64-w64-mingw32

Installation

Requires julia 1.3+. Install with Pkg, just like any other registered Julia package:

pkg> add Darknet  # Press ']' to enter the Pkg REPL mode.

Testing

using Darknet, Images
d = "/path/to/weights_and_config_files/"
weightsfile = "yolov3-tiny.weights"
cfgfile = "yolov3-tiny.cfg"
datafile = "coco.data"

imagefile = "/path/to/images/test.jpg"

net = Darknet.load_network(joinpath(d,cfgfile), joinpath(d,weightsfile),1)
meta = Darknet.get_metadata(joinpath(d,datafile));

Reading in an image from file:

# Read image using Darknet method
img = load(imagefile)  #Image for plotting in julia purposes only (below)
img_d = Darknet.load_image_color(imagefile,0,0);  #Darknet native way to read in image from file. Produces an image type with pointers

or from an array in julia memory:

# Send image via an image in julia memory
img = convert(Array{Float32}, load(imagefile)) #Read in array via a julia method
img_d = Darknet.array_to_image(img) #Darknet image type with pointers to source data

or for looping through images from julia, avoid reallocation due to permuted dims:

img = convert(Array{Float32}, load(imagefile)) #Read in array via a julia method

# Darknet flips the first 2 dims of an image (cols,rows,colorchannels)
# so preallocate a permuted dims array to prevent reallocation in 
if size(img,3) > 1 #if more than 1 color channel 
    img_permuted = Array{Float32}(undef,size(img,2),size(img,1),size(img,3)) 
else
    img_permuted = Array{Float32}(undef,size(img,2),size(img,1)) 
end

img_d = Darknet.array_to_image(img,img_permuted) #Darknet image type with pointers to source data

Run detection

results = Darknet.detect(net,meta,img_d,thresh=0.1,nms=0.3)

Preview result using Makie:

using Makie, GeometryTypes
scene = Scene(resolution = size(img'))
image!(scene,img',scale_plot = false)

for res in results
    bbox = res[3]
    poly!(scene,[Rectangle{Float32}(bbox[1]-(bbox[3]/2),bbox[2]-(bbox[4]/2),bbox[3],bbox[4])],color=RGBA(0,1,0,clamp(conf,0.05,0.5)))
end
scene

darknet.jl's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

darknet.jl's Issues

GPU?

Hello!
two questions:

  • are you planning to keep building the binaries every time AlexeyAB pushes to master?
  • is GPU support planned? How can I help?

conf is undefined to display result

I am trying to execute final code to display result but I am getting error of 'conf is undefined'.

`using Makie, GeometryTypes
scene = Scene(resolution = size(img'))
image!(scene,img',scale_plot = false)

for res in results
bbox = res[3]
poly!(scene,[Rectangle{Float32}(bbox[1]-(bbox[3]/2),bbox[2]-(bbox[4]/2),bbox[3],bbox[4])],color=RGBA(0,1,0,clamp(conf,0.05,0.5)))
end
scene`

How can I execute above code?

Or is there any way to save result as image?

TagBot trigger issue

This issue is used to trigger TagBot; feel free to unsubscribe.

If you haven't already, you should update your TagBot.yml to include issue comment triggers.
Please see this post on Discourse for instructions and more details.

If you'd like for me to do this for you, comment TagBot fix on this issue.
I'll open a PR within a few hours, please be patient!

use of `pointer` function causes memory corruption

Calling the pointer function causes Julia to reuse or clear the underlying memory as soon as possible, as there is no possible way for Julia to track future uses of the pointer. Therefore these are not legal:

return image(w,h,c,pointer(arr_permuted))

return image(w,h,c,pointer(arr_permuted))

return image(w,h,c,pointer(arr_permuted))

return image(w,h,c,pointer(arr_permuted))

and are the reason this package fails tests sometimes, such as:
https://s3.amazonaws.com/julialang-reports/nanosoldier/pkgeval/by_date/2021-02/22/Darknet.1.7.0-DEV-10bea8758a.log

Instead, these need to be copied into Libc.malloc memory or otherwise teach Darknet.jl to keep track of both the original array and C representation of it.

I suggest defining a Julia-compatible wrapper similar to the following (modulo any typos and such):

struct Image{N}
    w::Cint
    h::Cint
    c::Cint
    data::Array{Cfloat, N}
end
Base.cconvert(::Type{image}, im::Image) = im
Base.unsafe_convert(::Type{image}, im::Image) = image(im.w, im.h, im.c, pointer(im.data))

And changing those statements to return Image(...) instead :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.