Closed Rafagd closed 5 years ago
Hi, @Rafagd, thanks for questions!
I found this might be caused by the incompatibility of @tf.function
and @private_method
. The function tl.utils.fit
internally calls the function tl.utils._train_step
which is by default decorated with tf.function
for speedup. I tried two things:
@tf.function
of tl.utils._train_step
and then every thing works well.@private_method
of the _PS
function of tl.layers.SubpixelConv1d
and then everything works well too.The reason why @tf.function
conflicts with @private_method
is still unclear to me. Currently, I think the simplest way to solve this issue is to remove the @private_method
decorator of tl.layers.SubpixelConv1d
. @zsdonghao @JingqingZ Is it OK to do this? What's the initial reason to decorate it as private_method?
BTW, the above script is not runnable, try this one:
#!/usr/bin/python3
import tensorflow as tf
import tensorlayer as tl
import numpy as np
inputs = tl.layers.Input((1, 2, 2))
prev = tl.layers.SubpixelConv1d(2, in_channels=2)(inputs)
model = tl.models.Model(inputs, prev)
train_batch = np.array([1, 2, 3, 4]).reshape((1,2,2)).astype(np.float)
train_batch_y = train_batch.reshape((1, 4, 1))
valid_batch = train_batch
valid_batch_y = train_batch_y
tl.utils.fit(model,
train_op=tf.optimizers.Adam(learning_rate=0.0001),
cost=tf.losses.MeanSquaredError(),
X_train=train_batch, y_train=train_batch_y,
batch_size=len(train_batch), n_epoch=20, X_val=valid_batch, y_val=valid_batch_y, eval_train=True,
)
I can't see any problem to remove the @private_method of SubpixelConv1d.
Thanks for the correction! I was in a bit of a hurry when I was writing that minimal example.
@Rafagd The problem is fixed by PR #1025. Try install the latest version of TensorLayer:
pip3 install https://github.com/tensorlayer/tensorlayer/archive/master.zip
New Issue Checklist
Issue Description
The SubpixelConv1d class decorates the method _PS as @private_method, but when its own forward method calls the _PS function, the decorator for some reason gets confused and can't detect it's a valid use of the method and raises the exception.
Reproducible Code