R.Falque
R.Falque

Reputation: 944

How to write a net with a Memory Data Layer using pycaffe?

It is possible to write a caffe prototxt in pycaffe with a hdf5 data layer from the following lines:

import caffe
from caffe import layers as L

def logreg(hdf5, batch_size):
    n = caffe.NetSpec()
    n.data, n.label = L.HDF5Data(batch_size = batch_size, source = hdf5, ntop = 2)
    n.ip1 = L.InnerProduct(n.data, num_output = 2, weight_filler = dict(type='xavier'))
    n.accuracy = L.Accuracy(n.ip1, n.label)
    n.loss = L.SoftmaxWithLoss(n.ip1, n.label)
    return n.to_proto()

with open('models/logreg_auto_train.prototxt', 'w') as f:
    f.write(str(logreg('data/train.txt', chunck_size)))

Is it possible to use a similar method to write a prototxt that has a Memory Data Layer?

Upvotes: 3

Views: 1810

Answers (1)

Douglas Dawson
Douglas Dawson

Reputation: 556

Try something like this:

import caffe
from caffe import layers as L

def logreg(height, width, channels, batch_size):
    n = caffe.NetSpec()
    n.data = L.MemoryData(batch_size = batch_size, height = height, width = width, channels = channels)
    n.ip1 = L.InnerProduct(n.data, num_output = 2, weight_filler = dict(type='xavier'))
    return n.to_proto()

with open('models/logreg_memdata.prototxt', 'w') as f:
    f.write(str(logreg(128,128,3, chunck_size)))

Upvotes: 3

Related Questions