mxnet icon indicating copy to clipboard operation
mxnet copied to clipboard

Creating a layer-by-layer network

Open dma100180 opened this issue 9 years ago • 2 comments

MyData2.zip

Hi, I have a model of a layer that I would like to train, to then use both weights and Bias as a parameter to create a new layer:

DataNeurona<- read.csv("D:/DATOS_PROYECTO/MyData2.csv",sep = ",", header = T)

DataNeurona<-as.matrix(DataNeurona) #Duplico la ultima fila para luego hacer el test con ella: DataNeurona<-rbind(DataNeurona,DataNeurona[length(DataNeurona[,1]),])

NumTest<-2 train.ind<-c(41:(length(DataNeurona[,1])-NumTest)) train.x<-DataNeurona[train.ind,-(length(DataNeurona[1,]))] train.y<-DataNeurona[train.ind,length(DataNeurona[1,])] test.x<-DataNeurona[-c(1:41,train.ind),-length(DataNeurona[1,])] test.y<-DataNeurona[-c(1:41,train.ind),length(DataNeurona[1,])]

data <- mx.symbol.Variable("data") #w = mx.symbol.Variable('myweight')

fc1<-mx.symbol.FullyConnected(data, name="fc1", num_hidden=50, weights(ww)) act1<-mx.symbol.Activation(fc1,name="sigmoid1",act_type="sigmoid")

fc2<-mx.symbol.FullyConnected(act1,name="fc2",num_hidden=1) lro=mx.symbol.LinearRegressionOutput(data=fc2, grad.scale=1) mx.set.seed(0) train_iter = mx.io.arrayiter(data = t(train.x), label = t(train.y)) model <- mx.model.FeedForward.create(symbol= lro, X=train_iter, ctx=mx.cpu(2),
num.round=50, #optimizer = initialize=mx.init.uniform(0.7), array.batch.size=3, learning.rate=0.01, momentum=0.9,
eval.metric=mx.metric.mse)

My problem is that I can not find the way to create the layer later with the weights as parameter, I have tried with:

1 model$arg.params$fc1_weight fc1<-mx.symbol.FullyConnected(data, name="fc1", num_hidden=25, weights(model$arg.params$fc1_weight)) 2

model$arg.params$fc1_weight fc1<-mx.symbol.FullyConnected(data, name="fc1", num_hidden=25, weights=model$arg.params$fc1_weight, bias=model$arg.params$fc1_bias) 3 model$arg.params$fc1_weight fc1<-mx.symbol.FullyConnected(data, name="fc1", num_hidden=25, weights=model$arg.params[[fc1_weight]], bias=model$arg.params[[fc1_bias]]) 4 model.extract(model, "weights")

## ### **

** And I do not quite understand what I do wrong .... Greeting

dma100180 avatar Aug 22 '17 17:08 dma100180

@thirdwing could you help take a look at this issue?

eric-haibin-lin avatar Nov 17 '17 23:11 eric-haibin-lin

HOla, this I have not been able to create it as such, what I did was create the layers in a general way and put the parameters on the code .... so it served me, thank you

dma100180 avatar Feb 01 '18 19:02 dma100180