Add summary, returning probs & url
This commit is contained in:
parent
8532b3a518
commit
d4b5ecc0f9
|
@ -12,14 +12,21 @@
|
||||||
(get-labels! [_ image-data])
|
(get-labels! [_ image-data])
|
||||||
(get-detections! [_ image-data])
|
(get-detections! [_ image-data])
|
||||||
(get-highlights! [_ image-data])
|
(get-highlights! [_ image-data])
|
||||||
(get-probabilities! [_ image-data]))
|
(get-probabilities! [_ image-data])
|
||||||
|
(get-summary! [_ image-data]))
|
||||||
|
|
||||||
(defn- url->string [url] (.toExternalForm url))
|
(defn- url->string [url] (.toExternalForm url))
|
||||||
|
|
||||||
(defn- build-url [{:keys [scheme host port]}]
|
(defn- build-url [{:keys [scheme host port]}]
|
||||||
(url->string (URL. scheme host port "/images")))
|
(url->string (URL. scheme host port "/images")))
|
||||||
|
|
||||||
(defn- send-image! [url image-bytes]
|
(defn- send-image! [verbose url image-bytes]
|
||||||
|
(when verbose
|
||||||
|
(println (str "sending "
|
||||||
|
(count image-bytes)
|
||||||
|
" to "
|
||||||
|
url
|
||||||
|
" for object detection")))
|
||||||
(let [input-stream (ByteArrayInputStream. image-bytes)]
|
(let [input-stream (ByteArrayInputStream. image-bytes)]
|
||||||
(client/post url
|
(client/post url
|
||||||
{:multipart [{:name "image"
|
{:multipart [{:name "image"
|
||||||
|
@ -39,12 +46,10 @@
|
||||||
:reason (:reason-phrase resp)
|
:reason (:reason-phrase resp)
|
||||||
:response resp})))
|
:response resp})))
|
||||||
|
|
||||||
(defn- pthru [o] (pprint o) o)
|
(defrecord ObjectifierClient [scheme host port verbose]
|
||||||
|
|
||||||
(defrecord ObjectifierClient [scheme host port]
|
|
||||||
IObjectifierClient
|
IObjectifierClient
|
||||||
(get! [self image-data]
|
(get! [self image-data]
|
||||||
(process-response (send-image! (build-url (pthru self)) image-data)))
|
(process-response (send-image! verbose (build-url self) image-data)))
|
||||||
|
|
||||||
(get-labels! [self image-data]
|
(get-labels! [self image-data]
|
||||||
(-> (get! self image-data)
|
(-> (get! self image-data)
|
||||||
|
@ -61,10 +66,18 @@
|
||||||
(get-probabilities! [self image-data]
|
(get-probabilities! [self image-data]
|
||||||
(into {}
|
(into {}
|
||||||
(map (juxt (comp keyword :label) :confidence))
|
(map (juxt (comp keyword :label) :confidence))
|
||||||
(get-detections! self image-data))))
|
(get-detections! self image-data)))
|
||||||
|
|
||||||
|
(get-summary! [self image-data]
|
||||||
|
(let [result (get! self image-data)]
|
||||||
|
{:output (:output result)
|
||||||
|
:objects (into {}
|
||||||
|
(map (juxt (comp keyword :label) :confidence))
|
||||||
|
(get-detections! self image-data))})))
|
||||||
|
|
||||||
(defn define-connection
|
(defn define-connection
|
||||||
[& {:keys [scheme host port]
|
[& {:keys [scheme host port verbose]
|
||||||
:or {scheme "http"
|
:or {scheme "http"
|
||||||
port 80}}]
|
port 80
|
||||||
(->ObjectifierClient scheme host port))
|
verbose false}}]
|
||||||
|
(->ObjectifierClient scheme host port verbose))
|
||||||
|
|
Loading…
Reference in New Issue