apache / mxnet

Lightweight, Portable, Flexible Distributed/Mobile Deep Learning with Dynamic, Mutation-aware Dataflow Dep Scheduler; for Python, R, Julia, Scala, Go, Javascript and more
https://mxnet.apache.org
Apache License 2.0
20.77k stars 6.8k forks source link

About Neural Style python code transfer into R code issue #1945

Open fr407041 opened 8 years ago

fr407041 commented 8 years ago

Dear all

I try to transfer Neural Style python code into R code and here is my source code in github link .

I meet a issue in transfer this python code

# style gradient
for i in range(len(model_executor.style)):
       model_executor.style[i].copyto(gram_executor[i].data)
       gram_executor[i].executor.forward()
       gram_executor[i].executor.backward([gram_executor[i].executor.outputs[0] - style_array[i]])

In my R code, it's row : 262 - 274 , below is my R code

      for( i in 1:length(executor$outputs[-length(executor$outputs)]) ) { # i = 1
        arg.arrays = arg.array.func( executor = gram_executor[i][[1]]$executor , ctx = dev )
          for( name in names( gram_executor[i][[1]]$executor$arg.arrays) ) { # name = "data"
              if (name == "conv") {
                arg.arrays[name] = executor$outputs[-length(executor$outputs)][i]
              } else {
                arg.arrays[name] = executor$outputs[-length(executor$outputs)][i]
              }
          }
        mx.exec.update.arg.arrays(gram_executor[i][[1]]$executor, arg.arrays )
        mx.exec.forward(gram_executor[i][[1]]$executor)
        temp = gram_executor[i][[1]]$executor$outputs[[1]] - style_array[[i]]
        gram_executor[i][[1]]$executor$backward( list( temp ) )

I get an issue like below

>         temp = gram_executor[i][[1]]$executor$outputs[[1]] - style_array[[i]]
Why

Although the object temp is really the result of

gram_executor[i][[1]]$executor$outputs[[1]] - style_array[[i]]

but the complier return "Why" information. And then I try the below code

gram_executor[i][[1]]$executor$backward( list( temp ) )

I found gram_executor[i].data_grad[:] isn't updated (it's still zero matrix , in my R code it is equivalent to gram_executor[i][[1]]$executor$aux.arrays[[1]] {in the row : 277} )

I have no hint to solve this problem. (PS. Sorry for my poor English, I am a chinese, if you can't understand my question, I can write the problem in chinese)

tqchen commented 8 years ago

cc @thirdwing

thirdwing commented 8 years ago

OK. I finally finished papers I need to submit. I will look into this and other issues.

thirdwing commented 8 years ago

@fr407041 Do you mind sharing a link to your code?

fr407041 commented 8 years ago

To thirdwing, I don't mind. This is the github link .

rocalabern commented 8 years ago

No solution for now, right?

fr407041 commented 8 years ago

Yes, it seems no solution for now....