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.
#13385 [Clojure] - Turn examples into integration tests
- Loading branch information
Showing
28 changed files
with
841 additions
and
34 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
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
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
39 changes: 39 additions & 0 deletions
39
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,39 @@ | ||
;; | ||
;; 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] | ||
[clojure.string :as s] | ||
[org.apache.clojure-mxnet.context :as context] | ||
[org.apache.clojure-mxnet.module :as module] | ||
[imclassification.train-mnist :as mnist])) | ||
|
||
(defn- file-to-filtered-seq [file] | ||
(->> | ||
file | ||
(io/file) | ||
(io/reader) | ||
(line-seq) | ||
(filter #(not (s/includes? % "mxnet_version"))))) | ||
|
||
(deftest mnist-two-epochs-test | ||
(module/save-checkpoint (mnist/start [(context/cpu)] 2) {:prefix "target/test" :epoch 2}) | ||
(is (= | ||
(file-to-filtered-seq "test/test-symbol.json.ref") | ||
(file-to-filtered-seq "target/test-symbol.json")))) |
105 changes: 105 additions & 0 deletions
105
contrib/clojure-package/examples/imclassification/test/test-symbol.json.ref
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,105 @@ | ||
{ | ||
"nodes": [ | ||
{ | ||
"op": "null", | ||
"name": "data", | ||
"inputs": [] | ||
}, | ||
{ | ||
"op": "null", | ||
"name": "fc1_weight", | ||
"attrs": {"num_hidden": "128"}, | ||
"inputs": [] | ||
}, | ||
{ | ||
"op": "null", | ||
"name": "fc1_bias", | ||
"attrs": {"num_hidden": "128"}, | ||
"inputs": [] | ||
}, | ||
{ | ||
"op": "FullyConnected", | ||
"name": "fc1", | ||
"attrs": {"num_hidden": "128"}, | ||
"inputs": [[0, 0, 0], [1, 0, 0], [2, 0, 0]] | ||
}, | ||
{ | ||
"op": "Activation", | ||
"name": "relu1", | ||
"attrs": {"act_type": "relu"}, | ||
"inputs": [[3, 0, 0]] | ||
}, | ||
{ | ||
"op": "null", | ||
"name": "fc2_weight", | ||
"attrs": {"num_hidden": "64"}, | ||
"inputs": [] | ||
}, | ||
{ | ||
"op": "null", | ||
"name": "fc2_bias", | ||
"attrs": {"num_hidden": "64"}, | ||
"inputs": [] | ||
}, | ||
{ | ||
"op": "FullyConnected", | ||
"name": "fc2", | ||
"attrs": {"num_hidden": "64"}, | ||
"inputs": [[4, 0, 0], [5, 0, 0], [6, 0, 0]] | ||
}, | ||
{ | ||
"op": "Activation", | ||
"name": "relu2", | ||
"attrs": {"act_type": "relu"}, | ||
"inputs": [[7, 0, 0]] | ||
}, | ||
{ | ||
"op": "null", | ||
"name": "fc3_weight", | ||
"attrs": {"num_hidden": "10"}, | ||
"inputs": [] | ||
}, | ||
{ | ||
"op": "null", | ||
"name": "fc3_bias", | ||
"attrs": {"num_hidden": "10"}, | ||
"inputs": [] | ||
}, | ||
{ | ||
"op": "FullyConnected", | ||
"name": "fc3", | ||
"attrs": {"num_hidden": "10"}, | ||
"inputs": [[8, 0, 0], [9, 0, 0], [10, 0, 0]] | ||
}, | ||
{ | ||
"op": "null", | ||
"name": "softmax_label", | ||
"inputs": [] | ||
}, | ||
{ | ||
"op": "SoftmaxOutput", | ||
"name": "softmax", | ||
"inputs": [[11, 0, 0], [12, 0, 0]] | ||
} | ||
], | ||
"arg_nodes": [0, 1, 2, 5, 6, 9, 10, 12], | ||
"node_row_ptr": [ | ||
0, | ||
1, | ||
2, | ||
3, | ||
4, | ||
5, | ||
6, | ||
7, | ||
8, | ||
9, | ||
10, | ||
11, | ||
12, | ||
13, | ||
14 | ||
], | ||
"heads": [[13, 0, 0]], | ||
"attrs": {"mxnet_version": ["int", 10400]} | ||
} |
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))) |
Oops, something went wrong.