Comments (13)
When I add a SquareLossMaker instead of a SoftMaxLayer, I got a crash.
I'm using the python API
from deepcl.
Can you provide the exact script you're trying please? (Also: what OS? what version of python?)
from deepcl.
OS: Mac Os 10.11.2
Python: 2.7.10
For the code, the output should be a single float number, so I use the SquareLossMaker layer. Taking the provided example with modification, it gives someting like this:
net = PyDeepCL.NeuralNet(cl, 1, 28) net.addLayer(PyDeepCL.NormalizationLayerMaker().translate(-0.5).scale(1 / 255.0)) net.addLayer(PyDeepCL.ConvolutionalMaker().numFilters(8).filterSize(5).padZeros().biased()) net.addLayer(PyDeepCL.PoolingMaker().poolingSize(2)) net.addLayer(PyDeepCL.FullyConnectedMaker().numPlanes(1).imageSize(1)) net.addLayer(PyDeepCL.SquareLossMaker())
The python console print these following messages:
created netLearner
statefultimer v0.7
forward try kernel 0
... not plausibly optimal, skipping
forward try kernel 1
... seems valid
ForwardAuto: kernel 1 10ms
forward try kernel 0
... not plausibly optimal, skipping
forward try kernel 1
... seems valid
ForwardAuto: kernel 1 0ms
from deepcl.
Ah. What are you using as the targets? Targets will be different dimensions when using squared loss. Should match the output dimensions of the network.
from deepcl.
(ie, can you provide your complete test script please? but ideally, as simple a script as possible ,that replicates the problem)
from deepcl.
Ah, I looked a bit more closely at your network. Ok, so it has a single float output, sounds good.
from deepcl.
The following runs ok for me. Not saying it's learning anything, but it's not crashing:
#!/usr/bin/python
from __future__ import print_function
import array
import PyDeepCL
import sys
print('imports done')
cl = PyDeepCL.DeepCL()
net = PyDeepCL.NeuralNet(cl)
sgd = PyDeepCL.SGD(cl, 0.002, 0)
sgd.setMomentum(0.0001)
net = PyDeepCL.NeuralNet(cl, 1, 28)
net.addLayer(PyDeepCL.NormalizationLayerMaker().translate(-0.5).scale(1 / 255.0))
net.addLayer(PyDeepCL.ConvolutionalMaker().numFilters(8).filterSize(5).padZeros().biased())
net.addLayer(PyDeepCL.PoolingMaker().poolingSize(2))
net.addLayer(PyDeepCL.FullyConnectedMaker().numPlanes(1).imageSize(1))
net.addLayer(PyDeepCL.SquareLossMaker())
print(net.asString())
N = 1280
batchSize = 128
planes = 1
size = 28
numEpochs = 30
images = array.array('f', [0] * (N*planes*size*size))
targets = array.array('f', [0] * N)
net.setBatchSize(batchSize)
for epoch in range(numEpochs):
print('epoch', epoch)
numRight = 0
context = PyDeepCL.TrainingContext(epoch, 0)
for batch in range(N // batchSize):
sgd.train(
net,
context,
images[batch * batchSize * planes * size * size:],
targets[batch * batchSize:])
from deepcl.
Make sure to change from sgd.trainFromLabels
to sgd.train
by the way. train
expects float targets. trainFromLabels
expects integer labels.
from deepcl.
I try to fit the MNIST data set in a regressor way (why not). Just to test the code. The output explode and gives nan from the 2 nd epoch.
It's not clear for me how to do the prediction once the network is train (I think it with the forward function, and the get output from last layer, but the sizes doesn't fit...)
#!/usr/bin/python
# -*- coding: utf-8 -*-
from __future__ import print_function
import array
import PyDeepCL
import numpy as np
print('imports done')
path = "/Users/gmilani/cnn_data/"
mnistFilePath = path + 't10k-images-idx3-ubyte'
cl = PyDeepCL.DeepCL()
net = PyDeepCL.NeuralNet(cl)
net.addLayer(PyDeepCL.InputLayerMaker().numPlanes(1).imageSize(28))
net.addLayer(PyDeepCL.NormalizationLayerMaker().translate(-0.5).scale(1 / 255.0))
net.addLayer(PyDeepCL.ConvolutionalMaker().numFilters(8).filterSize(5).padZeros().biased())
net.addLayer(PyDeepCL.ActivationMaker().relu())
net.addLayer(PyDeepCL.PoolingMaker().poolingSize(2))
net.addLayer(PyDeepCL.ConvolutionalMaker().numFilters(8).filterSize(5).padZeros().biased())
net.addLayer(PyDeepCL.ActivationMaker().relu())
net.addLayer(PyDeepCL.PoolingMaker().poolingSize(3))
net.addLayer(PyDeepCL.FullyConnectedMaker().numPlanes(150).imageSize(1).biased())
net.addLayer(PyDeepCL.ActivationMaker().tanh())
net.addLayer(PyDeepCL.FullyConnectedMaker().numPlanes(1).imageSize(1).biased())
net.addLayer(PyDeepCL.SquareLossMaker())
sgd = PyDeepCL.SGD(cl, 0.002, 0)
sgd.setMomentum(0.0001)
print(net.asString())
N = 1280
batchSize = 128
planes = 1
size = 28
numEpochs = 3
images = array.array('f', [0] * (N * planes * size * size))
targets = array.array('i', [0] * N)
PyDeepCL.GenericLoader.load(mnistFilePath, images, targets, 0, N)
images = array.array('f', images)
targets = array.array('f', np.array(targets))
np_targets = np.array(targets)
print(np_targets)
precision = np.mean(np.array(targets))
net.setBatchSize(batchSize)
for epoch in range(0, numEpochs):
print('epoch', epoch)
context = PyDeepCL.TrainingContext(epoch, 0)
for batch in range(N // batchSize):
sgd.train(
net,
context,
images[batch * batchSize * planes * size * size:],
targets[batch * batchSize:])
net.forward(images[batch * batchSize * planes * size * size:])
# test new getLabels() method:
if batch == 0:
lastLayer = net.getLastLayer()
predictions = lastLayer.getOutput()
# precision = np.mean((np.array(predictions) - np_targets) ** 2)
# print('precision : ', precision)
print(predictions)
from deepcl.
I've just changed the parameters and it works well !
sgd = PyDeepCL.SGD(cl, 0.0002, 0)
sgd.setMomentum(0.000001)
from deepcl.
Cool. So it's working ok?
from deepcl.
Yes, it's training quite well. You can close the issue. You may want to do an example for regressor with this try for the documentation (?).
from deepcl.
Yes, it's training quite well. You can close the issue.
Ok, cool :-)
from deepcl.
Related Issues (20)
- MNIST data format HOT 1
- Python Q-Learning - Add Dropout Layout causes runtime error HOT 11
- can passed all test in #ad1ab61, but not now (#b256220) HOT 48
- function "NetLearner::learn" is deprecated, how to train a network by the new method? HOT 2
- How to use ExpectedData correctly in training? HOT 2
- tutorial and documentation is very less
- integrated demo HOT 2
- could deepcl run on FPGAs? HOT 1
- deepcl_predict HOT 5
- does the Neural network created on GPU? HOT 3
- captcha
- pip with windows does not work
- Need cythonize
- deepcl_unittests not running in CentOS 7. HOT 2
- opencl 1.1?
- Feature Request: Add Mish activation HOT 3
- How to set stride of conv layer? HOT 2
- Implementation of DNN on FPGA HOT 2
- Any examples for face detection?
- is there any ConvTranspose2d?
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 deepcl.