forked from apache/mxnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
apache#13385 [Clojure] - Turn examples into integration tests
- Loading branch information
Showing
24 changed files
with
716 additions
and
30 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
44 changes: 44 additions & 0 deletions
44
...package/examples/cnn-text-classification/test/cnn_text_classification/classifier_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,44 @@ | ||
;; | ||
;; 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 cnn-text-classification.classifier-test | ||
(:require | ||
[clojure.test :refer :all] | ||
[org.apache.clojure-mxnet.module :as module] | ||
[org.apache.clojure-mxnet.ndarray :as ndarray] | ||
[org.apache.clojure-mxnet.util :as util] | ||
[org.apache.clojure-mxnet.context :as context] | ||
[cnn-text-classification.classifier :as classifier])) | ||
|
||
; | ||
; The one and unique classifier test | ||
; | ||
(deftest classifier-test | ||
(let [train | ||
(classifier/train-convnet | ||
{:devs [(context/default-context)] | ||
:embedding-size 50 | ||
:batch-size 10 | ||
:test-size 100 | ||
:num-epoch 1 | ||
:max-examples 1000})] | ||
(is (= ["data"] (util/scala-vector->vec (module/data-names train)))) | ||
(is (= 20 (count (ndarray/->vec (-> train module/outputs first first))))))) | ||
;(prn (util/scala-vector->vec (data-shapes train))) | ||
;(prn (util/scala-vector->vec (label-shapes train))) | ||
;(prn (output-names train)) | ||
;(prn (output-shapes train)) |
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
25 changes: 25 additions & 0 deletions
25
contrib/clojure-package/examples/gan/test/gan/gan_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,25 @@ | ||
;; | ||
;; 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 gan.gan_test | ||
(:require | ||
[gan.gan-mnist :refer :all] | ||
[org.apache.clojure-mxnet.context :as context] | ||
[clojure.test :refer :all])) | ||
|
||
(deftest check-pdf | ||
(train [(context/cpu)] 1)) |
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
28 changes: 28 additions & 0 deletions
28
contrib/clojure-package/examples/imclassification/test/imclassification/train_mnist_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,28 @@ | ||
;; | ||
;; 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 imclassification.train-mnist-test | ||
(:require | ||
[clojure.test :refer :all] | ||
[clojure.java.io :as io] | ||
[org.apache.clojure-mxnet.context :as context] | ||
[org.apache.clojure-mxnet.module :as module] | ||
[imclassification.train-mnist :as mnist])) | ||
|
||
(deftest mnist-two-epochs-test | ||
(module/save-checkpoint (mnist/start [(context/cpu)] 2) {:prefix "target/test" :epoch 2}) | ||
(is (= (slurp "test/test-0002.params") (slurp "target/test-0002.params")))) |
29 changes: 29 additions & 0 deletions
29
contrib/clojure-package/examples/module/test/mnist_mlp_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,29 @@ | ||
;; | ||
;; 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 mnist-mlp-test | ||
(:require | ||
[mnist-mlp :refer :all] | ||
[org.apache.clojure-mxnet.context :as context] | ||
[clojure.test :refer :all])) | ||
|
||
(deftest run-those-tests | ||
(let [devs [(context/cpu)]] | ||
(run-intermediate-level-api :devs devs) | ||
(run-intermediate-level-api :devs devs :load-model-epoch (dec num-epoch)) | ||
(run-high-level-api devs) | ||
(run-prediction-iterator-api devs) | ||
(run-predication-and-calc-accuracy-manually devs))) |
26 changes: 26 additions & 0 deletions
26
contrib/clojure-package/examples/multi-label/test/multi_label_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,26 @@ | ||
;; | ||
;; 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 multi_label_test | ||
(:require | ||
[multi-label.core :as label] | ||
[clojure.java.io :as io] | ||
[org.apache.clojure-mxnet.context :as context] | ||
[clojure.test :refer :all])) | ||
|
||
(deftest run-multi-label | ||
(label/train [(context/cpu)])) |
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
56 changes: 56 additions & 0 deletions
56
contrib/clojure-package/examples/neural-style/test/neural_style/vgg_19_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,56 @@ | ||
;; | ||
;; 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 neural-style.vgg-19-test | ||
(:require | ||
[clojure.test :refer :all] | ||
[mikera.image.core :as img] | ||
[clojure.java.io :as io] | ||
[org.apache.clojure-mxnet.ndarray :as ndarray] | ||
[org.apache.clojure-mxnet.context :as context] | ||
[neural-style.core :as neural])) | ||
|
||
(defn pic-to-ndarray-vec[path] | ||
(-> path | ||
img/load-image | ||
neural/image->ndarray | ||
ndarray/->vec)) | ||
|
||
(defn last-modified-check[x] | ||
(let [t (- (System/currentTimeMillis) (.lastModified x)) ] | ||
(if (> 10000 t) ; 10 seconds | ||
x | ||
(throw (Exception. (str "Generated File Too Old: (" t " ms) [" x "]")))))) | ||
|
||
(defn latest-pic-to-ndarray-vec[folder] | ||
(->> folder | ||
io/as-file | ||
(.listFiles) | ||
(sort-by #(.lastModified %)) | ||
last | ||
(last-modified-check) | ||
(.getPath) | ||
pic-to-ndarray-vec)) | ||
|
||
; | ||
; The one and unique classifier test | ||
; | ||
(deftest vgg-19-test | ||
(neural/train [(context/cpu)] 3) | ||
(is (= | ||
(latest-pic-to-ndarray-vec "output") | ||
(pic-to-ndarray-vec "test/ref_out_2.png")))) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Oops, something went wrong.