You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2018/09/21 04:34:28 UTC

[GitHub] jeremiedb commented on issue #12431: [R] use of mx.io.arrayiter completely crashes R environment

jeremiedb commented on issue #12431: [R] use of mx.io.arrayiter completely crashes R environment
URL: https://github.com/apache/incubator-mxnet/issues/12431#issuecomment-423410481
 
 
   I think the issue comes from the evaluation metric. The following code include a modified rmse metric that flatten the pred and label vector. I think it's bug that the eval metric fails when the predictions are not in a flat setting, I'll open a PR to get it fixed. 
   
   ```
   data.A <- mx.nd.random.normal(shape = c(3,3,1,10))
   data.A.2 <- mx.nd.random.normal(shape = c(3,3,1,10))
   
   batch_size <- 5
   
   train_iter = mx.io.arrayiter(data = as.array(data.A),
                                label = as.array(data.A.2),
                                batch.size = batch_size)
   
   data <- mx.symbol.Variable('data')
   label <- mx.symbol.Variable('label')
   
   conv_1 <- mx.symbol.Convolution(data= data, kernel = c(1,1), num_filter = 4, name="conv_1")
   conv_act_1 <- mx.symbol.Activation(data= conv_1, act_type = "relu", name="conv_act_1")
   flat <- mx.symbol.flatten(data = conv_act_1,  name="flatten")
   fcl_1 <- mx.symbol.FullyConnected(data = flat, num_hidden = 9, name="fc_1")
   fcl_2 <- mx.symbol.reshape(fcl_1, shape=c(3, 3, 1, batch_size))
   NN_Model <- mx.symbol.LinearRegressionOutput(data=fcl_2 , label=label, name="lro")
   
   fcl_2$infer.shape(list(data = c(3,3,1,batch_size)))
   NN_Model$infer.shape(list(data = c(3,3,1,batch_size)))
   
   mx.metric.rmse <- mx.metric.custom("rmse", function(label, pred) {
     pred <- mx.nd.reshape(pred, shape = -1)
     label <- mx.nd.reshape(label, shape = -1)
     res <- mx.nd.sqrt(mx.nd.mean(mx.nd.square(label-pred)))
     return(as.array(res))
   })
   
   mx.set.seed(99)
   autoencoder <- mx.model.FeedForward.create(
     NN_Model, 
     X = train_iter, 
     initializer = mx.init.uniform(0.01),
     ctx=mx.cpu(), 
     num.round=5,
     eval.metric = mx.metric.rmse, 
     optimizer = mx.opt.create("sgd"),
     verbose = TRUE)
   
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services