Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

[Clojure] examples with opencv4/origami #13813

Merged
merged 1 commit into from
Jan 16, 2019

Conversation

hellonico
Copy link
Contributor

Description

This PR uses OpenCV/Origami as the image manipulation library.

Checklist

Essentials

Please feel free to remove inapplicable items for your PR.

  • The PR title starts with [MXNET-$JIRA_ID], where $JIRA_ID refers to the relevant JIRA issue created (except PRs with tiny changes)
  • Changes are complete (i.e. I finished coding on this PR)
  • [x ] All changes have test coverage:
  • Unit tests are added for small changes to verify correctness (e.g. adding a new operator)
  • Nightly tests are added for complicated/long-running ones (e.g. changing distributed kvstore)
  • Build tests will be added for build configuration changes (e.g. adding a new build option with NCCL)
  • Code is well-documented:
  • For user-facing API changes, API doc string has been updated.
  • For new C++ functions in header files, their functionalities and arguments are documented.
  • For new examples, README.md is added to explain the what the example does, the source of the dataset, expected performance on test set and reference to the original paper if applicable
  • Check the API doc at http:https://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
  • [x ] To the my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

Changes

Basically using library: [origami "4.0.0-2"] with imports:

[opencv4.core :as cv]
[opencv4.utils :as cvu]

Whenever possible.

Comments

@anirudhacharya
Copy link
Member

@mxnet-label-bot add [pr-awaiting-review]

@marcoabreu marcoabreu added the pr-awaiting-review PR is waiting for code review label Jan 9, 2019
hellonico added a commit to hellonico/incubator-mxnet that referenced this pull request Jan 11, 2019
Copy link
Member

@gigasquid gigasquid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

_ (Core/flip img result (int 0))]
result)
img))))
(cv/>> (new-mat height width CV_8UC1) (byte-array raw-data)))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

neat threading :)

(println "The nd image size is:" {:height h :width w})
(-> simg
(cv/convert-to! cv/CV_8SC3 0.5)
(cv/add! (cv/new-scalar -103.939 -116.779 -123.68) )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool - this is a nice way to do this

(let [h (.height simg) w (.width simg)]
(println "The nd image size is:" {:height h :width w})
(-> simg
(cv/convert-to! cv/CV_8SC3 0.5)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does the 0.5 in convert-to! do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its scaling the bytes to match the new format. (-128 > 128 instead of 0 > 255)

[(conj rs r) (conj gs g) (conj bs b)]))
[[] [] []]
pixels)]
(when show? (img/show image))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to show the image to the user if the show? flag is true? imshow?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just added !

[opencv4.core :refer [FONT_HERSHEY_PLAIN imread imwrite new-point put-text! rectangle]]))

(defn black-boxes! [img results]
(doseq [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like the formatting is a bit off in this function - I know if varies from editor to editor. There is a tool to keep the style consistent between contributors, (I should run this more often I know :) )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed. updated the formatting.

@@ -18,8 +18,8 @@
(defproject neural-style "0.1.0-SNAPSHOT"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran the example - works great!

:plugins [[lein-cljfmt "0.5.7"]]
:aliases {"sample-detector" ["run" "--" "-m" "models/resnet50_ssd/resnet50_ssd_model" "-i" "images/dog.jpg" "-d" "images/"]}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice alias - can you please add to the README too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added!

@@ -106,10 +127,9 @@
factory
{:contexts [(context/default-context)]})]
(println "Object detection on a single image")
(print-predictions (detect-single-image detector input-image) width height)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we also leave the printing of the predictions to the console in as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re-added.


(defn detect-images-in-dir
"Detect objects in all jpg images in the directory"
[detector input-dir]
[detector input-dir output-dir]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we make the default output-dir for the example results or image-results?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"results" it is.

@@ -20,6 +20,7 @@
[org.apache.clojure-mxnet.infer :as infer]
[org.apache.clojure-mxnet.layout :as layout]
[clojure.java.io :as io]
[infer.draw :as draw]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran the example and the drawing of the bounding boxes is fantastic!

Can you please merge this PR with master because the output of the predictions has now changed shape a bit
#13864

Object detection now returns a map
{:class car, :prob 0.99847263, :x-min 0.6097917, :y-min 0.1406818, :x-max 0.8906532, :y-max 0.29426125}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing out ! Re-Merged with master and fixed.

hellonico added a commit to hellonico/incubator-mxnet that referenced this pull request Jan 13, 2019
hellonico added a commit to hellonico/incubator-mxnet that referenced this pull request Jan 13, 2019
@gigasquid
Copy link
Member

Thanks for addressing the feedback so quickly @hellonico 😄
I plan to take one more test drive through it shortly 🏎

@gigasquid gigasquid changed the title [WIP] examples with opencv4/origami [Clojure] examples with opencv4/origami Jan 15, 2019
@gigasquid
Copy link
Member

Thanks for all your hard work on making this possible @hellonico - It works great - tested on OSX and Linux 🎆

@gigasquid gigasquid merged commit 754ff76 into apache:master Jan 16, 2019
piyushghai added a commit to piyushghai/incubator-mxnet that referenced this pull request Jan 22, 2019
stephenrawls pushed a commit to stephenrawls/incubator-mxnet that referenced this pull request Feb 16, 2019
haohuanw pushed a commit to haohuanw/incubator-mxnet that referenced this pull request Jun 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Clojure pr-awaiting-review PR is waiting for code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants