Comments (3)
First, I don't know if anyone tried filling the gorgonia graph with PyTorch trained weight. Since gorgonia never guaranteed the implementation here is identical to any other framework. But it will make gorgonia more popular if we do that.
Second, a quick check that makes sure you also use float32 in your PyTorch code.
Third, maybe you can upload your whole code to GitHub to make it easy to debug.
To clarify, I'm also quite new to gorgonia. Maybe @chewxy @owulveryck has a better suggestion?
from gorgonia.
I have never used redisai, to figure out what's going wrong, show your code maybe?
from gorgonia.
/* Thanks for your reply. I am a new hand in golang and deep learning.
// Following is my Lenet code. It do same thing like pytorch do.
*/
package cifar10
import (
"log"
"github.com/RedisAI/redisai-go/redisai"
G "gorgonia.org/gorgonia"
"gorgonia.org/tensor"
)
var dt = tensor.Float32
// redisai keys: a key => a tensor
var redisaiKeys = []string{
"infty.lenet.conv.0.weight",
"infty.lenet.conv.3.weight",
"infty.lenet.fc.0.weight",
"infty.lenet.fc.2.weight",
"infty.lenet.fc.4.weight"}
type LeNet struct {
g *G.ExprGraph
learnables G.Nodes
}
func NewLeNet(g *G.ExprGraph) *LeNet {
lenet := LeNet{}
lenet.g = g
lenet.learnables = make(G.Nodes, 5)
lenet.learnables[0] = G.NewTensor(g, dt, 4, G.WithShape(6, 3, 5, 5), G.WithName("w0"), G.WithInit(G.ValuesOf(float32(1))))
lenet.learnables[1] = G.NewTensor(g, dt, 4, G.WithShape(16, 6, 5, 5), G.WithName("w1"), G.WithInit(G.ValuesOf(float32(1))))
lenet.learnables[2] = G.NewMatrix(g, dt, G.WithShape(400, 120), G.WithName("w2"), G.WithInit(G.ValuesOf(float32(1))))
lenet.learnables[3] = G.NewMatrix(g, dt, G.WithShape(120, 84), G.WithName("w3"), G.WithInit(G.ValuesOf(float32(1))))
lenet.learnables[4] = G.NewMatrix(g, dt, G.WithShape(84, 10), G.WithName("w4"), G.WithInit(G.ValuesOf(float32(1))))
// get pretrained weights from redisai and write to nodes
client := redisai.Connect("redis://localhost:6379", nil)
for i := 0; i < len(lenet.learnables); i++ {
w, err := client.TensorGet(redisaiKeys[i], redisai.TensorContentTypeValues)
if err == nil {
wt := tensor.New(tensor.WithShape(lenet.learnables[i].Shape()...), tensor.WithBacking(w[2]))
G.Let(lenet.learnables[i], wt)
} else {
log.Fatalln(err)
}
}
return &lenet
}
func (m *LeNet) convFwd(x *G.Node, w *G.Node) *G.Node {
c0 := G.Must(G.Conv2d(x, w, tensor.Shape{5, 5}, []int{0, 0}, []int{1, 1}, []int{1, 1}))
a0 := G.Must(G.Rectify(c0))
p0 := G.Must(G.MaxPool2D(a0, tensor.Shape{2, 2}, []int{0, 0}, []int{2, 2}))
return p0
}
func (m *LeNet) fcFwd(x *G.Node, w *G.Node) *G.Node {
fc0 := G.Must(G.Mul(x, w))
a0 := G.Must(G.Rectify(fc0))
return a0
}
func (m *LeNet) fwd(x *G.Node) (out *G.Node, err error) {
var l0, l1, r2, l3, l4, l5 *G.Node
// Conv
l0 = m.convFwd(x, m.learnables[0])
l1 = m.convFwd(l0, m.learnables[1])
// flattern
b, c, h, w := l1.Shape()[0], l1.Shape()[1], l1.Shape()[2], l1.Shape()[3]
r2 = G.Must(G.Reshape(l1, tensor.Shape{b, c * h * w}))
// full connect
l3 = m.fcFwd(r2, m.learnables[2])
l4 = m.fcFwd(l3, m.learnables[3])
l5 = m.fcFwd(l4, m.learnables[4])
out, err = G.SoftMax(l5, 1)
return out, err
}
from gorgonia.
Related Issues (20)
- Inference in go (trained in python and deploy in golang) HOT 1
- I need help deploying NLP and Neural Network model HOT 1
- Getting start code failed to run HOT 1
- Stacking multiple tensors
- Unable to import gorgonia.org/gorgonia/examples/mnist HOT 3
- There is an inexplicable error when running convnet_cuda, and I have no clue to solve it. Can you provide some ideas? HOT 3
- convnet with cuda (v11) support not working HOT 2
- If there is any function would be used like deconv2D?
- examples/charRNN Crashes When Run HOT 5
- Critical dualValue bug? HOT 7
- No examples folder for v0.9.16 and v0.9.17
- Unexpected behaviour with Add() and Sub()
- "go get -u gorgonia.org/gorgonia" - error undefined: arrowArray.Interface HOT 1
- panic on parallel runner HOT 1
- Support for OpenCL and multiple GPUs, such as Intel Graphics and AMD. HOT 1
- BatchedMatMul bug when applying to 1-shape matrix
- Please may you tag a new version HOT 1
- OneHot op
- Using a node twice without it getting changed in-place HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gorgonia.