Giter Site home page Giter Site logo

Float values as output about deepcl HOT 13 CLOSED

hughperkins avatar hughperkins commented on June 12, 2024
Float values as output

from deepcl.

Comments (13)

gilliM avatar gilliM commented on June 12, 2024

When I add a SquareLossMaker instead of a SoftMaxLayer, I got a crash.
I'm using the python API

from deepcl.

hughperkins avatar hughperkins commented on June 12, 2024

Can you provide the exact script you're trying please? (Also: what OS? what version of python?)

from deepcl.

gilliM avatar gilliM commented on June 12, 2024

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.

hughperkins avatar hughperkins commented on June 12, 2024

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.

hughperkins avatar hughperkins commented on June 12, 2024

(ie, can you provide your complete test script please? but ideally, as simple a script as possible ,that replicates the problem)

from deepcl.

hughperkins avatar hughperkins commented on June 12, 2024

Ah, I looked a bit more closely at your network. Ok, so it has a single float output, sounds good.

from deepcl.

hughperkins avatar hughperkins commented on June 12, 2024

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.

hughperkins avatar hughperkins commented on June 12, 2024

Make sure to change from sgd.trainFromLabels to sgd.train by the way. train expects float targets. trainFromLabels expects integer labels.

from deepcl.

gilliM avatar gilliM commented on June 12, 2024

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.

gilliM avatar gilliM commented on June 12, 2024

I've just changed the parameters and it works well !

sgd = PyDeepCL.SGD(cl, 0.0002, 0)
sgd.setMomentum(0.000001)

from deepcl.

hughperkins avatar hughperkins commented on June 12, 2024

Cool. So it's working ok?

from deepcl.

gilliM avatar gilliM commented on June 12, 2024

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.

hughperkins avatar hughperkins commented on June 12, 2024

Yes, it's training quite well. You can close the issue.

Ok, cool :-)

from deepcl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.