Skip to content

Commit

Permalink
Revert "[MXNET-1260] Float64 DType computation support in Scala/Java (a…
Browse files Browse the repository at this point in the history
…pache#13678)"

This reverts commit ed7ca26.
  • Loading branch information
piyushghai committed Jan 22, 2019
1 parent a879e55 commit dc54202
Show file tree
Hide file tree
Showing 35 changed files with 294 additions and 1,251 deletions.
1 change: 0 additions & 1 deletion CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ List of Contributors
* [Yuxi Hu](/~https://github.com/yuxihu)
* [Harsh Patel](/~https://github.com/harshp8l)
* [Xiao Wang](/~https://github.com/BeyonderXX)
* [Piyush Ghai](/~https://github.com/piyushghai)

Label Bot
---------
Expand Down
242 changes: 125 additions & 117 deletions contrib/clojure-package/src/org/apache/clojure_mxnet/infer.clj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
(ns org.apache.clojure-mxnet.infer
(:refer-clojure :exclude [type])
(:require [org.apache.clojure-mxnet.context :as context]
[org.apache.clojure-mxnet.dtype :as dtype]
[org.apache.clojure-mxnet.io :as mx-io]
[org.apache.clojure-mxnet.shape :as shape]
[org.apache.clojure-mxnet.util :as util]
Expand Down Expand Up @@ -63,12 +62,10 @@
(defprotocol AImageClassifier
(classify-image
[wrapped-image-classifier image]
[wrapped-image-classifier image topk]
[wrapped-image-classifier image topk dtype])
[wrapped-image-classifier image topk])
(classify-image-batch
[wrapped-image-classifier images]
[wrapped-image-classifier images topk]
[wrapped-image-classifier images topk dtype]))
[wrapped-image-classifier images topk]))

(defprotocol AObjectDetector
(detect-objects
Expand All @@ -83,8 +80,7 @@

(extend-protocol APredictor
WrappedPredictor
(predict
[wrapped-predictor inputs]
(predict [wrapped-predictor inputs]
(util/validate! ::wrapped-predictor wrapped-predictor
"Invalid predictor")
(util/validate! ::vec-of-float-arrays inputs
Expand All @@ -105,50 +101,62 @@

(extend-protocol AClassifier
WrappedClassifier
(classify
([wrapped-classifier inputs]
(classify wrapped-classifier inputs nil))
([wrapped-classifier inputs topk]
(util/validate! ::wrapped-classifier wrapped-classifier
"Invalid classifier")
(util/validate! ::vec-of-float-arrays inputs
"Invalid inputs")
(util/validate! ::nil-or-int topk "Invalid top-K")
(util/coerce-return-recursive
(.classify (:classifier wrapped-classifier)
(util/vec->indexed-seq inputs)
(util/->int-option topk)))))
(classify-with-ndarray
([wrapped-classifier inputs]
(classify-with-ndarray wrapped-classifier inputs nil))
([wrapped-classifier inputs topk]
(util/validate! ::wrapped-classifier wrapped-classifier
"Invalid classifier")
(util/validate! ::vec-of-ndarrays inputs
"Invalid inputs")
(util/validate! ::nil-or-int topk "Invalid top-K")
(util/coerce-return-recursive
(.classifyWithNDArray (:classifier wrapped-classifier)
(util/vec->indexed-seq inputs)
(util/->int-option topk)))))
(classify [wrapped-classifier inputs]
(util/validate! ::wrapped-classifier wrapped-classifier
"Invalid classifier")
(util/validate! ::vec-of-float-arrays inputs
"Invalid inputs")
(classify wrapped-classifier inputs nil))
(classify [wrapped-classifier inputs topk]
(util/validate! ::wrapped-classifier wrapped-classifier
"Invalid classifier")
(util/validate! ::vec-of-float-arrays inputs
"Invalid inputs")
(util/validate! ::nil-or-int topk "Invalid top-K")
(util/coerce-return-recursive
(.classify (:classifier wrapped-classifier)
(util/vec->indexed-seq inputs)
(util/->int-option topk))))
(classify-with-ndarray [wrapped-classifier inputs]
(util/validate! ::wrapped-classifier wrapped-classifier
"Invalid classifier")
(util/validate! ::vec-of-ndarrays inputs
"Invalid inputs")
(classify-with-ndarray wrapped-classifier inputs nil))
(classify-with-ndarray [wrapped-classifier inputs topk]
(util/validate! ::wrapped-classifier wrapped-classifier
"Invalid classifier")
(util/validate! ::vec-of-ndarrays inputs
"Invalid inputs")
(util/validate! ::nil-or-int topk "Invalid top-K")
(util/coerce-return-recursive
(.classifyWithNDArray (:classifier wrapped-classifier)
(util/vec->indexed-seq inputs)
(util/->int-option topk))))
WrappedImageClassifier
(classify
([wrapped-image-classifier inputs]
(classify wrapped-image-classifier inputs nil))
([wrapped-image-classifier inputs topk]
(util/validate! ::wrapped-image-classifier wrapped-image-classifier
"Invalid classifier")
(util/validate! ::vec-of-float-arrays inputs
"Invalid inputs")
(util/validate! ::nil-or-int topk "Invalid top-K")
(util/coerce-return-recursive
(.classify (:image-classifier wrapped-image-classifier)
(util/vec->indexed-seq inputs)
(util/->int-option topk)))))
(classify-with-ndarray
([wrapped-image-classifier inputs]
(classify-with-ndarray wrapped-image-classifier inputs nil))
([wrapped-image-classifier inputs topk]
(classify [wrapped-image-classifier inputs]
(util/validate! ::wrapped-image-classifier wrapped-image-classifier
"Invalid classifier")
(util/validate! ::vec-of-float-arrays inputs
"Invalid inputs")
(classify wrapped-image-classifier inputs nil))
(classify [wrapped-image-classifier inputs topk]
(util/validate! ::wrapped-image-classifier wrapped-image-classifier
"Invalid classifier")
(util/validate! ::vec-of-float-arrays inputs
"Invalid inputs")
(util/validate! ::nil-or-int topk "Invalid top-K")
(util/coerce-return-recursive
(.classify (:image-classifier wrapped-image-classifier)
(util/vec->indexed-seq inputs)
(util/->int-option topk))))
(classify-with-ndarray [wrapped-image-classifier inputs]
(util/validate! ::wrapped-image-classifier wrapped-image-classifier
"Invalid classifier")
(util/validate! ::vec-of-ndarrays inputs
"Invalid inputs")
(classify-with-ndarray wrapped-image-classifier inputs nil))
(classify-with-ndarray [wrapped-image-classifier inputs topk]
(util/validate! ::wrapped-image-classifier wrapped-image-classifier
"Invalid classifier")
(util/validate! ::vec-of-ndarrays inputs
Expand All @@ -157,83 +165,83 @@
(util/coerce-return-recursive
(.classifyWithNDArray (:image-classifier wrapped-image-classifier)
(util/vec->indexed-seq inputs)
(util/->int-option topk))))))
(util/->int-option topk)))))

(s/def ::image #(instance? BufferedImage %))
(s/def ::dtype #{dtype/UINT8 dtype/INT32 dtype/FLOAT16 dtype/FLOAT32 dtype/FLOAT64})

(extend-protocol AImageClassifier
WrappedImageClassifier
(classify-image
([wrapped-image-classifier image]
(classify-image wrapped-image-classifier image nil dtype/FLOAT32))
([wrapped-image-classifier image topk]
(classify-image wrapped-image-classifier image topk dtype/FLOAT32))
([wrapped-image-classifier image topk dtype]
(util/validate! ::wrapped-image-classifier wrapped-image-classifier
"Invalid classifier")
(util/validate! ::image image "Invalid image")
(util/validate! ::nil-or-int topk "Invalid top-K")
(util/validate! ::dtype dtype "Invalid dtype")
(util/coerce-return-recursive
(.classifyImage (:image-classifier wrapped-image-classifier)
image
(util/->int-option topk)
dtype))))
(classify-image-batch
([wrapped-image-classifier images]
(classify-image-batch wrapped-image-classifier images nil dtype/FLOAT32))
([wrapped-image-classifier images topk]
(classify-image-batch wrapped-image-classifier images topk dtype/FLOAT32))
([wrapped-image-classifier images topk dtype]
(util/validate! ::wrapped-image-classifier wrapped-image-classifier
"Invalid classifier")
(util/validate! ::nil-or-int topk "Invalid top-K")
(util/validate! ::dtype dtype "Invalid dtype")
(util/coerce-return-recursive
(.classifyImageBatch (:image-classifier wrapped-image-classifier)
images
(util/->int-option topk)
dtype)))))
(classify-image [wrapped-image-classifier image]
(util/validate! ::wrapped-image-classifier wrapped-image-classifier
"Invalid classifier")
(util/validate! ::image image "Invalid image")
(classify-image wrapped-image-classifier image nil))
(classify-image [wrapped-image-classifier image topk]
(util/validate! ::wrapped-image-classifier wrapped-image-classifier
"Invalid classifier")
(util/validate! ::image image "Invalid image")
(util/validate! ::nil-or-int topk "Invalid top-K")
(util/coerce-return-recursive
(.classifyImage (:image-classifier wrapped-image-classifier)
image
(util/->int-option topk))))
(classify-image-batch [wrapped-image-classifier images]
(util/validate! ::wrapped-image-classifier wrapped-image-classifier
"Invalid classifier")
(classify-image-batch wrapped-image-classifier images nil))
(classify-image-batch [wrapped-image-classifier images topk]
(util/validate! ::wrapped-image-classifier wrapped-image-classifier
"Invalid classifier")
(util/validate! ::nil-or-int topk "Invalid top-K")
(util/coerce-return-recursive
(.classifyImageBatch (:image-classifier wrapped-image-classifier)
images
(util/->int-option topk)))))

(extend-protocol AObjectDetector
WrappedObjectDetector
(detect-objects
([wrapped-detector image]
(detect-objects wrapped-detector image nil))
([wrapped-detector image topk]
(detect-objects [wrapped-detector image]
(util/validate! ::wrapped-detector wrapped-detector
"Invalid object detector")
(util/validate! ::image image "Invalid image")
(util/validate! ::nil-or-int topk "Invalid top-K")
(util/coerce-return-recursive
(.imageObjectDetect (:object-detector wrapped-detector)
image
(util/->int-option topk)))))
(detect-objects-batch
([wrapped-detector images]
(detect-objects-batch wrapped-detector images nil))
([wrapped-detector images topk]
(util/validate! ::wrapped-detector wrapped-detector
"Invalid object detector")
(util/validate! ::nil-or-int topk "Invalid top-K")
(util/coerce-return-recursive
(.imageBatchObjectDetect (:object-detector wrapped-detector)
images
(util/validate! ::image image "Invalid image")
(detect-objects wrapped-detector image nil))
(detect-objects [wrapped-detector image topk]
(util/validate! ::wrapped-detector wrapped-detector
"Invalid object detector")
(util/validate! ::image image "Invalid image")
(util/validate! ::nil-or-int topk "Invalid top-K")
(util/coerce-return-recursive
(.imageObjectDetect (:object-detector wrapped-detector)
image
(util/->int-option topk))))
(detect-objects-batch [wrapped-detector images]
(util/validate! ::wrapped-detector wrapped-detector
"Invalid object detector")
(detect-objects-batch wrapped-detector images nil))
(detect-objects-batch [wrapped-detector images topk]
(util/validate! ::wrapped-detector wrapped-detector
"Invalid object detector")
(util/validate! ::nil-or-int topk "Invalid top-K")
(util/coerce-return-recursive
(.imageBatchObjectDetect (:object-detector wrapped-detector)
images
(util/->int-option topk))))
(detect-objects-with-ndarrays [wrapped-detector input-arrays]
(util/validate! ::wrapped-detector wrapped-detector
"Invalid object detector")
(util/validate! ::vec-of-ndarrays input-arrays
"Invalid inputs")
(detect-objects-with-ndarrays wrapped-detector input-arrays nil))
(detect-objects-with-ndarrays [wrapped-detector input-arrays topk]
(util/validate! ::wrapped-detector wrapped-detector
"Invalid object detector")
(util/validate! ::vec-of-ndarrays input-arrays
"Invalid inputs")
(util/validate! ::nil-or-int topk "Invalid top-K")
(util/coerce-return-recursive
(.objectDetectWithNDArray (:object-detector wrapped-detector)
(util/vec->indexed-seq input-arrays)
(util/->int-option topk)))))
(detect-objects-with-ndarrays
([wrapped-detector input-arrays]
(detect-objects-with-ndarrays wrapped-detector input-arrays nil))
([wrapped-detector input-arrays topk]
(util/validate! ::wrapped-detector wrapped-detector
"Invalid object detector")
(util/validate! ::vec-of-ndarrays input-arrays
"Invalid inputs")
(util/validate! ::nil-or-int topk "Invalid top-K")
(util/coerce-return-recursive
(.objectDetectWithNDArray (:object-detector wrapped-detector)
(util/vec->indexed-seq input-arrays)
(util/->int-option topk))))))

(defprotocol AInferenceFactory
(create-predictor [factory] [factory opts])
Expand Down Expand Up @@ -327,7 +335,7 @@
[image input-shape-vec]
(util/validate! ::image image "Invalid image")
(util/validate! (s/coll-of int?) input-shape-vec "Invalid shape vector")
(ImageClassifier/bufferedImageToPixels image (shape/->shape input-shape-vec) dtype/FLOAT32))
(ImageClassifier/bufferedImageToPixels image (shape/->shape input-shape-vec)))

(s/def ::image-path string?)
(s/def ::image-paths (s/coll-of ::image-path))
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
(:require [clojure.spec.alpha :as s]
[t6.from-scala.core :refer [$ $$] :as $]
[clojure.string :as string]
[org.apache.clojure-mxnet.primitives :as primitives]
[org.apache.clojure-mxnet.shape :as mx-shape])
(:import (org.apache.mxnet NDArray)
(scala Product Tuple2 Tuple3)
Expand All @@ -37,8 +36,7 @@
"byte<>" "byte-array"
"java.lang.String<>" "vec-or-strings"
"org.apache.mxnet.NDArray" "ndarray"
"org.apache.mxnet.Symbol" "sym"
"org.apache.mxnet.MX_PRIMITIVES$MX_PRIMITIVE_TYPE" "double-or-float"})
"org.apache.mxnet.Symbol" "sym"})

(def symbol-param-coerce {"java.lang.String" "sym-name"
"float" "num"
Expand Down Expand Up @@ -146,8 +144,6 @@
(and (get targets "int<>") (vector? param)) (int-array param)
(and (get targets "float<>") (vector? param)) (float-array param)
(and (get targets "java.lang.String<>") (vector? param)) (into-array param)
(and (get targets "org.apache.mxnet.MX_PRIMITIVES$MX_PRIMITIVE_TYPE") (instance? Float param)) (primitives/mx-float param)
(and (get targets "org.apache.mxnet.MX_PRIMITIVES$MX_PRIMITIVE_TYPE") (number? param)) (primitives/mx-double param)
:else param))

(defn nil-or-coerce-param [param targets]
Expand Down Expand Up @@ -181,7 +177,6 @@
(instance? Map return-val) (scala-map->map return-val)
(instance? Tuple2 return-val) (tuple->vec return-val)
(instance? Tuple3 return-val) (tuple->vec return-val)
(primitives/primitive? return-val) (primitives/->num return-val)
:else return-val))

(defn coerce-return-recursive [return-val]
Expand Down
Loading

0 comments on commit dc54202

Please sign in to comment.