How to implement this Python class? #1277
AntonLobach
started this conversation in
General
Replies: 2 comments
-
|
Hi @AntonLobach, The following approach seems to have worked for me: I directly implemented the (ns module
(:import
torch
[torch.nn :as nn]
[torch.nn.functional :as F]))
(deftype MyModule [^:mutable conv1 ^:mutable conv2]
^:abstract nn/Module
(__init__ [self]
(.__init__ (super))
(set! conv1 (nn/Conv2d 1 20 5))
(set! conv2 (nn/Conv2d 20 20 5))
nil)
(forward [self x]
(try
(-> x
(conv1)
(F/relu)
(conv2)
(F/relu))
(catch Exception e
(println :error e)))))
(def model (MyModule))
(def x (torch/randn 4 1 28 28))
(println (model x))
;; => tensor([[[[2.2859e-02, 0.0000e+00, 0.0000e+00, ..., 1.5598e-02,
;; => 0.0000e+00, 0.0000e+00],
;; => ... |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Hi @ikappaki, Ah, I see, I was actually so close to correctly implementing it, thanks a lot! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I would like to translate this Python code to Basilisp, but I'm stuck.
Basically, I'm not sure how to correctly translate the init method and how to invoke call methods.
I've checked the test suite and the docs, but couldn't come up with anything working based off of it.
My attempt:
Beta Was this translation helpful? Give feedback.
All reactions