Skip to content

Instantly share code, notes, and snippets.


Carin Meier gigasquid

View GitHub Profile
View seaborn-data.clj
(ns gigasquid.seaborn
(:require [libpython-clj.require :refer [require-python]]
[libpython-clj.python :as py :refer [py. py.. py.-]]
[gigasquid.plot :as plot]
[ :as csv]))
(require-python '[seaborn :as sns])
(require-python '[matplotlib.pyplot :as pyplot])
(require-python '[pandas :as pandas])
gigasquid / gpt2.clj
Created Jan 10, 2020
GPT2 with libpython-clj
View gpt2.clj
(ns gigasquid.gpt2
(:require [libpython-clj.require :refer [require-python]]
[libpython-clj.python :as py]))
; - OpenAI GPT-2
(require-python '(transformers))
(require-python '(torch))
gigasquid / mxnet.clj
Last active Jan 14, 2020
View mxnet.clj
(ns gigasquid.mxnet
(:require [libpython-clj.require :refer [require-python]]
[libpython-clj.python :as py]
[clojure.string :as string]))
(require-python '(mxnet mxnet.ndarray mxnet.module
(require-python '(mxnet.test_utils))
(require-python '(mxnet.initializer))
(require-python '(mxnet.metric))
(require-python '(mxnet.symbol))
gigasquid /
Last active Jan 28, 2019
Next Journal Deps for Clojure MXNet
#!/usr/bin/env bash
sudo apt-get update || true
sudo apt-get install -y build-essential
sudo apt-get install -y software-properties-common
sudo apt-get install -y libatlas-base-dev
sudo apt-get install -y libopenblas-dev
sudo apt-get install -y libcurl3
sudo add-apt-repository ppa:timsc/opencv-3.4
sudo apt-get update
View mvninstall.txt
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] MXNet Scala Package - Parent
[INFO] MXNet Scala Package - Initializer
[INFO] MXNet Scala Package - Initializer Native
[INFO] MXNet Scala Package - Macros
[INFO] MXNet Scala Package - Native
[INFO] MXNet Scala Package - Core
View generator.clj
(ns dev.generator
(:require [clojure.reflect :as r])
(:import (org.apache.mxnet NDArray Symbol))
(->> (:members (r/reflect (Symbol/api)))
(filter #(clojure.string/includes? (:name %) "FullyConnected")))
;;=> output
View mnist-model.clj
(as-> (sym/variable "data") data
(sym/fully-connected "fc1" {:data data :num-hidden 128})
(sym/activation "relu1" {:data data :act-type "relu"})
(sym/fully-connected "fc2" {:data data :num-hidden 64})
(sym/activation "relu2" {:data data :act-type "relu"})
(sym/fully-connected "fc3" {:data data :num-hidden 10})
(sym/softmax-output "softmax" {:data data}))
View tabby.clj
(predict "" true)
;; ({:prob 0.294283, :label "n02123045 tabby, tabby cat"}
;; {:prob 0.25543088, :label "n02122878 tabby, queen"}
;; {:prob 0.18031825, :label "n02123159 tiger cat"}
;; {:prob 0.06245274, :label "n01318894 pet"}
;; {:prob 0.04261507, :label "n02120997 feline, felid"})
View predict.clj
(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]})
View graal-exploration.clj
(ns graal-test.core
(:import (org.graalvm.polyglot Context)))
(def py-context (Context/create (into-array ["python"])))
(.eval py-context "python" "print('Hello polyglot world Python!');")
(.eval py-context "python" "
import time;
") ;=> #object[org.graalvm.polyglot.Value 0x4a6b3b70 "1.508202803249E9"]