tf-keras icon indicating copy to clipboard operation
tf-keras copied to clipboard

unable to save function, WeightNormalization with Conv1DTranspose error

Open binbinxue opened this issue 2 years ago • 5 comments
trafficstars

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 avatar Dec 22 '22 13:12 binbinxue

@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!

sushreebarsa avatar Jan 04 '23 05:01 sushreebarsa

@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 avatar Jan 04 '23 11:01 binbinxue

@binbinxue Thank you for the update! @SuryanarayanaY I was able to replicate this issue, please find the gist here. Thank you!

sushreebarsa avatar Jan 04 '23 15:01 sushreebarsa

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/

tilakrayal avatar Apr 21 '25 09:04 tilakrayal

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.

github-actions[bot] avatar May 06 '25 02:05 github-actions[bot]

This issue was closed because it has been inactive for 28 days. Please reopen if you'd like to work on this further.

github-actions[bot] avatar May 20 '25 02:05 github-actions[bot]