dmlc / MXNet.jl

MXNet Julia Package - flexible and efficient deep learning in Julia

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

UpSampling does not recognize num_args

holl- opened this issue · comments

commented

I am working on a convolutional auto-encoder using MXNet with Julia. As the inverse operation to pooling, I want to use 'mx.UpSampling'.
upsamp = mx.UpSampling(data=[X], scale=4, sample_type="nearest", num_args=1)
However, this line produces the following error claiming that num_args is set to zero, despite it being clearly set to one.
LoadError: MXNet.mx.MXError("value 0for Parameter num_args should be greater equal to 1")
The problem is similar to #72 where the issue appeared with the Concat method.

Hi, can you try instead doing:

mx.UpSampling(X, scale=4, sample_type="nearest")

This is due to the (unfortunate) fact that the API in the doc is for the underlying C++ call. The num_args argument should be automatically handled by the Julia wrapper.

commented

It works with your version! Thank you very much.
It would be nice, though, if this way of invoking the method was documented in the Julia API.

@holl- Yes, the same issue happens in some other similar operators such as Concat. And we should fix this.

@Holl,
Hi,
Haven't you implemented convolutional autoencoder yet?

commented

@AliShahin I have implemented it. However, I didn't use Upsampling after all, since my data is one-dimensional and as far as I know, UpSampling always increases width and height. I was able to get the Deconvolution to do the upsampling for me.

commented

Currently I have a two-layer convolutional autoencoder. There are still a couple of strange things about this, like using filters of length 9 in the encoder but of length 8 in the decoder. I had to do this to get the right dimensions, but any suggestions to how to handle this correctly would be appreciated. Also when adding deep layers in the middle, learning ceases.
My input data is one dimensional and has 256 features.

Here is the code:

X = mx.Variable(:data)
 Y = mx.Variable(:label)

X4D = mx.Reshape(data=X, shape=(1, size(data,1), 1, batch_size))
  conv1 = mx.Convolution(data=X4D, kernel=(1, 9), pad=(0, 4), num_filter=num_filter_1, name=:conv1) # 2D->3D
  act1 = mx.Activation(data=conv1, act_type=internal_act)
  pool1 = mx.Pooling(data=act1, kernel=(1, 4), stride=(1, 4), pool_type="max") # 256->64
  cdropout1 = mx.Dropout(data=pool1, p=conv_dropout)

  conv2 = mx.Convolution(data=cdropout1, kernel=(1, 9), pad=(0, 4), num_filter=num_filter_2, name=:conv2)
  act2 = mx.Activation(data=conv2, act_type=internal_act)
  pool2 = mx.Pooling(data=act2, kernel=(1, 4), stride=(1, 4), pool_type="max") # 64->16
  cdropout2 = mx.Dropout(data=pool2, p=conv_dropout)

  flat1 = mx.Flatten(cdropout2) # (batch_size, width, height=1)

  latent = mx.FullyConnected(data = flat1, num_hidden=latent_size, name=:latent)
  
  dec_fci = mx.FullyConnected(data=latent, num_hidden=16*num_filter_2, name=:blow_up) # sort values by location
  dec_fc1a = mx.Activation(data=dec_fci, act_type=internal_act)
  dec_fc1d = mx.Dropout(data=dec_fc1a, p=conv_dropout)

  LX4D = mx.Reshape(data=dec_fc1d, shape=(1, 16, num_filter_2, batch_size))
  deconv1 = mx.Deconvolution(data=LX4D, kernel=(1, 8), stride=(1, 4), pad=(0, 2), num_filter=num_filter_1, name=:deconv1)
  deconv1a = mx.Activation(data=deconv1, act_type=internal_act)
  ddropout1 = mx.Dropout(data=deconv1a, p=conv_dropout)

  deconv2 = mx.Deconvolution(data=ddropout1, kernel=(1, 8), stride=(1, 4), pad=(0, 2), num_filter=1, name=:deconv2)
  deconv2a = mx.Activation(data=deconv2, act_type=internal_act)

  flatdeconv2a = mx.Flatten(deconv2a, name=:out) # (batch_size, width, height=1)

  loss = mx.LinearRegressionOutput(data=flatdeconv2a, label=Y, name=:softmax)