tf-keras
tf-keras copied to clipboard
unable to save function, WeightNormalization with Conv1DTranspose error
System information.
- Have I written custom code (as opposed to using a stock example script provided in Keras): Yes
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Ubuntu 20.04
- TensorFlow installed from (source or binary): conda
- TensorFlow version (use command below): 2.11.0
- Python version: 3.9.0
- Bazel version (if compiling from source):
- GPU model and memory: RTX 3080Ti
- Exact command to reproduce:
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.layers import Conv1DTranspose
from tensorflow_addons import layers as addon_layers
model = keras.Sequential([
addon_layers.WeightNormalization(Conv1DTranspose(32, 16, 2, padding='same'))
])
model.build(input_shape=(None, None, 32))
tf.saved_model.save(model,'./2/')
Describe the problem. WeightNormalization wrapped around Conv1DTranspose trains ok, but when exporting to tf format it gives error with below message:
ValueError: Unable to save function b'__inference_conv1d_transpose_layer_call_and_return_conditional_losses_1421' because it captures graph tensor Tensor("compute_weights/mul:0", shape=(16, 32, 32), dtype=float32) from a parent function which cannot be converted to a constant with tf.get_static_value.
@binbinxue Sorry for the late response! Could you try to reshape it to occupy an extra dimension, run the deconvolution, and then reshape it back. Please refer to this doc and let us know if that helps? Thank you!
@binbinxue Sorry for the late response! Could you try to reshape it to occupy an extra dimension, run the deconvolution, and then reshape it back. Please refer to this doc and let us know if that helps? Thank you!
do you mean adding an extra dimension and then use Conv2DTranspose then apply weightNorm? as in https://github.com/TensorSpeech/TensorFlowTTS/blob/136877136355c82d7ba474ceb7a8f133bd84767e/tensorflow_tts/models/melgan.py#L62
I've also tried this before i raised the issue here, same problem with model saving
@binbinxue Thank you for the update! @SuryanarayanaY I was able to replicate this issue, please find the gist here. Thank you!
Could you try to explore reshaping the data to introduce an extra dimension, applying the deconvolution operation, and then reversing the reshaping process to return to the original data structure.
The Keras.Conv1D official documentation could be a useful reference for understanding the implications of this approach on the data and the deconvolution process. https://keras.io/api/layers/convolution_layers/convolution1d/
This issue is stale because it has been open for 14 days with no activity. It will be closed if no further activity occurs. Thank you.
This issue was closed because it has been inactive for 28 days. Please reopen if you'd like to work on this further.