Last active
August 24, 2018 22:04
-
-
Save gigasquid/4f595805400b29ebdb56531bfea40fa1 to your computer and use it in GitHub Desktop.
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
(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