Skip to content

Instantly share code, notes, and snippets.

@gigasquid
Last active August 24, 2018 22:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gigasquid/4f595805400b29ebdb56531bfea40fa1 to your computer and use it in GitHub Desktop.
Save gigasquid/4f595805400b29ebdb56531bfea40fa1 to your computer and use it in GitHub Desktop.
(defn predict [img-url show?]
(let [mod (m/load-checkpoint {:prefix (str model-dir "/resnet-152") :epoch 0})
labels (-> (slurp (str model-dir "/synset.txt"))
(string/split #"\n"))
nd-img (get-image img-url show?)
prob (-> mod
(m/bind {:for-training false
:data-shapes [{:name "data" :shape [1 num-channels h w]}]})
(m/forward {:data [nd-img]})
(m/outputs)
(ffirst))
prob-with-labels (mapv (fn [p l] {:prob p :label l})
(ndarray/->vec prob)
labels)]
(->> (sort-by :prob prob-with-labels)
(reverse)
(take 5))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment