thirdwing commented on issue #6629: Not enough information to get shape
URL:
https://github.com/apache/incubator-mxnet/issues/6629#issuecomment-321399282
With the latest version of mxnet from github, the code works well:
```r
library(mxnet)
train.x = matrix(data = rexp(200, rate = 10), nrow = 120, ncol = 6380)
train.y = matrix(data = rexp(6380, rate = 10), nrow = 120, ncol = 319)
# Reshape testing data
train.array <- train.x
dim(train.array) <- c(319, 20, 120)
dim(train.y) <- c(319, 120)
data <- mx.symbol.Variable("data")
# Define the first fully connected layer
fc1 <- mx.symbol.FullyConnected(data, num_hidden = 100)
act.fun <- mx.symbol.Activation(fc1, act_type = "relu") # create a hidden
layer with Rectified Linear Unit as its activation function.
output <- mx.symbol.FullyConnected(act.fun, num_hidden = 319)
# Customize loss function
label <- mx.symbol.Variable("label")
output_mean <- mx.symbol.mean(output)
label_mean <- mx.symbol.mean(label)
output_delta <- mx.symbol.broadcast_sub(output, output_mean)
label_delta <- mx.symbol.broadcast_sub(label, label_mean)
output_sqr <- mx.symbol.square(output_delta)
label_sqr <- mx.symbol.square(label_delta)
output_sd <- mx.symbol.sqrt(mx.symbol.sum(output_delta))
label_sd <- mx.symbol.sqrt(mx.symbol.sum(label_delta))
numerator <- mx.symbol.sum(output_delta * label_delta)
denominator <- output_sd * label_sd
lro <- mx.symbol.MakeLoss(numerator / denominator)
# Generate a new model
model <- mx.model.FeedForward.create(symbol = lro,
X = train.array,
y = train.y,
num.round = 5000,
array.batch.size = 1,
optimizer = "adam",
learning.rate = 0.0003,
eval.metric = mx.metric.rmse,
epoch.end.callback =
mx.callback.log.train.metric(20))
```
```
Start training with 1 devices
[1] Train-rmse=NaN
...
```
The output of `Makeloss` is the gradient, so the `mx.metric.rmse` produced
NaN.
If you are using the prebuilt pkg, please wait for the update. I will update
it soon.
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:
us...@infra.apache.org
With regards,
Apache Git Services