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
341fe62
commit fb7ee7f
Showing
6 changed files
with
260 additions
and
67 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
70 changes: 70 additions & 0 deletions
70
...lojure-package/examples/infer/imageclassifier/test/infer/imageclassifier_example_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,70 @@ | ||
;; 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 infer.imageclassifier-example-test | ||
(:require [infer.imageclassifier-example :refer [classify-single-image | ||
classify-images-in-dir]] | ||
[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 "models/") | ||
(def image-dir "images/") | ||
(def model-path-prefix (str model-dir "resnet-18/resnet-18")) | ||
(def image-file (str image-dir "kitten.jpg")) | ||
|
||
(when-not (.exists (io/file (str model-path-prefix "-symbol.json"))) | ||
(sh "./scripts/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) | ||
predictions (classify-single-image classifier image-file)] | ||
(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) | ||
batch-predictions (classify-images-in-dir classifier image-dir) | ||
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)))) |
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
66 changes: 66 additions & 0 deletions
66
.../clojure-package/examples/infer/objectdetector/test/infer/objectdetector_example_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,66 @@ | ||
;; 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 infer.objectdetector-example-test | ||
(:require [infer.objectdetector-example :refer [detect-single-image | ||
detect-images-in-dir]] | ||
[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 "models/") | ||
(def image-dir "images/") | ||
(def model-path-prefix (str model-dir "resnet50_ssd/resnet50_ssd_model")) | ||
(def image-file (str image-dir "dog.jpg")) | ||
|
||
(when-not (.exists (io/file (str model-path-prefix "-symbol.json"))) | ||
(sh "./scripts/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) | ||
predictions (detect-single-image detector image-file)] | ||
(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 (= ["car" "bicycle" "dog" "bicycle" "person"] | ||
(map first predictions))))) | ||
|
||
(deftest test-batch-detection | ||
(let [detector (create-detector) | ||
batch-predictions (detect-images-in-dir detector image-dir) | ||
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.