This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kedar Bellare
committed
Dec 22, 2018
1 parent
fb7ee7f
commit a15a098
Showing
17 changed files
with
306 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
contrib/clojure-package/scripts/infer/get_resnet_18_data.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/bin/bash | ||
|
||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
set -evx | ||
|
||
if [ ! -z "$MXNET_HOME" ]; then | ||
data_path="$MXNET_HOME/data" | ||
else | ||
MXNET_ROOT=$(cd "$(dirname $0)/../.."; pwd) | ||
data_path="$MXNET_ROOT/data" | ||
fi | ||
|
||
if [ ! -d "$data_path" ]; then | ||
mkdir -p "$data_path" | ||
fi | ||
|
||
resnet_18_data_path="$data_path/resnet-18" | ||
if [ ! -f "$resnet_18_data_path/resnet-18-0000.params" ]; then | ||
wget https://s3.us-east-2.amazonaws.com/scala-infer-models/resnet-18/resnet-18-symbol.json -P $resnet_18_data_path | ||
wget https://s3.us-east-2.amazonaws.com/scala-infer-models/resnet-18/resnet-18-0000.params -P $resnet_18_data_path | ||
wget https://s3.us-east-2.amazonaws.com/scala-infer-models/resnet-18/synset.txt -P $resnet_18_data_path | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/bin/bash | ||
|
||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
|
||
set -evx | ||
|
||
if [ ! -z "$MXNET_HOME" ]; then | ||
data_path="$MXNET_HOME/data" | ||
else | ||
MXNET_ROOT=$(cd "$(dirname $0)/../.."; pwd) | ||
data_path="$MXNET_ROOT/data" | ||
fi | ||
|
||
if [ ! -d "$data_path" ]; then | ||
mkdir -p "$data_path" | ||
fi | ||
|
||
resnet50_ssd_data_path="$data_path/resnet50_ssd" | ||
if [ ! -f "$resnet50_ssd_data_path/resnet50_ssd_model-0000.params" ]; then | ||
wget https://s3.amazonaws.com/model-server/models/resnet50_ssd/resnet50_ssd_model-symbol.json -P $resnet50_ssd_data_path | ||
wget https://s3.amazonaws.com/model-server/models/resnet50_ssd/resnet50_ssd_model-0000.params -P $resnet50_ssd_data_path | ||
wget https://s3.amazonaws.com/model-server/models/resnet50_ssd/synset.txt -P $resnet50_ssd_data_path | ||
fi |
69 changes: 69 additions & 0 deletions
69
contrib/clojure-package/test/org/apache/clojure_mxnet/infer/imageclassifier_test.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
;; Licensed to the Apache Software Foundation (ASF) under one or more | ||
;; contributor license agreements. See the NOTICE file distributed with | ||
;; this work for additional information regarding copyright ownership. | ||
;; The ASF licenses this file to You under the Apache License, Version 2.0 | ||
;; (the "License"); you may not use this file except in compliance with | ||
;; the License. You may obtain a copy of the License at | ||
;; | ||
;; http://www.apache.org/licenses/LICENSE-2.0 | ||
;; | ||
;; Unless required by applicable law or agreed to in writing, software | ||
;; distributed under the License is distributed on an "AS IS" BASIS, | ||
;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
;; See the License for the specific language governing permissions and | ||
;; limitations under the License. | ||
;; | ||
|
||
(ns org.apache.clojure-mxnet.infer.imageclassifier-test | ||
(:require [org.apache.clojure-mxnet.context :as context] | ||
[org.apache.clojure-mxnet.dtype :as dtype] | ||
[org.apache.clojure-mxnet.infer :as infer] | ||
[org.apache.clojure-mxnet.io :as mx-io] | ||
[org.apache.clojure-mxnet.layout :as layout] | ||
[clojure.java.io :as io] | ||
[clojure.java.shell :refer [sh]] | ||
[clojure.test :refer :all])) | ||
|
||
(def model-dir "data/") | ||
(def model-path-prefix (str model-dir "resnet-18/resnet-18")) | ||
|
||
(when-not (.exists (io/file (str model-path-prefix "-symbol.json"))) | ||
(sh "./scripts/infer/get_resnet_18_data.sh")) | ||
|
||
(defn create-classifier [] | ||
(let [descriptors [(mx-io/data-desc {:name "data" | ||
:shape [1 3 224 224] | ||
:layout layout/NCHW | ||
:dtype dtype/FLOAT32})] | ||
factory (infer/model-factory model-path-prefix descriptors)] | ||
(infer/create-image-classifier factory))) | ||
|
||
(deftest test-single-classification | ||
(let [classifier (create-classifier) | ||
image (infer/load-image-from-file "test/test-images/kitten.jpg") | ||
[predictions] (infer/classify-image classifier image 5)] | ||
(is (some? predictions)) | ||
(is (= 5 (count predictions))) | ||
(is (every? #(= 2 (count %)) predictions)) | ||
(is (every? #(string? (first %)) predictions)) | ||
(is (every? #(float? (second %)) predictions)) | ||
(is (every? #(< 0 (second %) 1) predictions)) | ||
(is (= ["n02123159 tiger cat" | ||
"n02124075 Egyptian cat" | ||
"n02123045 tabby, tabby cat" | ||
"n02127052 lynx, catamount" | ||
"n02128757 snow leopard, ounce, Panthera uncia"] | ||
(map first predictions))))) | ||
|
||
(deftest test-batch-classification | ||
(let [classifier (create-classifier) | ||
image-batch (infer/load-image-paths ["test/test-images/kitten.jpg" | ||
"test/test-images/Pug-Cookie.jpg"]) | ||
batch-predictions (infer/classify-image-batch classifier image-batch 5) | ||
predictions (first batch-predictions)] | ||
(is (some? batch-predictions)) | ||
(is (= 5 (count predictions))) | ||
(is (every? #(= 2 (count %)) predictions)) | ||
(is (every? #(string? (first %)) predictions)) | ||
(is (every? #(float? (second %)) predictions)) | ||
(is (every? #(< 0 (second %) 1) predictions)))) |
64 changes: 64 additions & 0 deletions
64
contrib/clojure-package/test/org/apache/clojure_mxnet/infer/objectdetector_test.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
;; Licensed to the Apache Software Foundation (ASF) under one or more | ||
;; contributor license agreements. See the NOTICE file distributed with | ||
;; this work for additional information regarding copyright ownership. | ||
;; The ASF licenses this file to You under the Apache License, Version 2.0 | ||
;; (the "License"); you may not use this file except in compliance with | ||
;; the License. You may obtain a copy of the License at | ||
;; | ||
;; http://www.apache.org/licenses/LICENSE-2.0 | ||
;; | ||
;; Unless required by applicable law or agreed to in writing, software | ||
;; distributed under the License is distributed on an "AS IS" BASIS, | ||
;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
;; See the License for the specific language governing permissions and | ||
;; limitations under the License. | ||
;; | ||
|
||
(ns org.apache.clojure-mxnet.infer.objectdetector-test | ||
(:require [org.apache.clojure-mxnet.context :as context] | ||
[org.apache.clojure-mxnet.dtype :as dtype] | ||
[org.apache.clojure-mxnet.infer :as infer] | ||
[org.apache.clojure-mxnet.io :as mx-io] | ||
[org.apache.clojure-mxnet.layout :as layout] | ||
[clojure.java.io :as io] | ||
[clojure.java.shell :refer [sh]] | ||
[clojure.test :refer :all])) | ||
|
||
(def model-dir "data/") | ||
(def model-path-prefix (str model-dir "resnet50_ssd/resnet50_ssd_model")) | ||
|
||
(when-not (.exists (io/file (str model-path-prefix "-symbol.json"))) | ||
(sh "./scripts/infer/get_ssd_data.sh")) | ||
|
||
(defn create-detector [] | ||
(let [descriptors [(mx-io/data-desc {:name "data" | ||
:shape [1 3 512 512] | ||
:layout layout/NCHW | ||
:dtype dtype/FLOAT32})] | ||
factory (infer/model-factory model-path-prefix descriptors)] | ||
(infer/create-object-detector factory))) | ||
|
||
(deftest test-single-detection | ||
(let [detector (create-detector) | ||
image (infer/load-image-from-file "test/test-images/kitten.jpg") | ||
[predictions] (infer/detect-objects detector image 5)] | ||
(is (some? predictions)) | ||
(is (= 5 (count predictions))) | ||
(is (every? #(= 2 (count %)) predictions)) | ||
(is (every? #(string? (first %)) predictions)) | ||
(is (every? #(= 5 (count (second %))) predictions)) | ||
(is (every? #(< 0 (first (second %)) 1) predictions)) | ||
(is (= "cat" (first (first predictions)))))) | ||
|
||
(deftest test-batch-detection | ||
(let [detector (create-detector) | ||
image-batch (infer/load-image-paths ["test/test-images/kitten.jpg" | ||
"test/test-images/Pug-Cookie.jpg"]) | ||
batch-predictions (infer/detect-objects-batch detector image-batch 5) | ||
predictions (first batch-predictions)] | ||
(is (some? batch-predictions)) | ||
(is (= 5 (count predictions))) | ||
(is (every? #(= 2 (count %)) predictions)) | ||
(is (every? #(string? (first %)) predictions)) | ||
(is (every? #(= 5 (count (second %))) predictions)) | ||
(is (every? #(< 0 (first (second %)) 1) predictions)))) |
Oops, something went wrong.