Skip to content

A keras model containing a tf.tile op layer with a tensor in the multiples arg fails when saving to hdf5 #32672

@currivan

Description

@currivan

Please make sure that this is a bug. As per our GitHub Policy, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:bug_template

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): Yes
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): MacOS 10.14.5
  • Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device:
  • TensorFlow installed from (source or binary): binary
  • TensorFlow version (use command below): v2.0.0-rc0-101-gd2d2566eef 2.0.0-rc1
  • Python version: Python 3.6.8 :: Anaconda, Inc.
  • Bazel version (if compiling from source):
  • GCC/Compiler version (if compiling from source):
  • CUDA/cuDNN version:
  • GPU model and memory:

You can collect some of this information using our environment capture
script
You can also obtain the TensorFlow version with: 1. TF 1.0: python -c "import tensorflow as tf; print(tf.GIT_VERSION, tf.VERSION)" 2. TF 2.0: python -c "import tensorflow as tf; print(tf.version.GIT_VERSION, tf.version.VERSION)"

Describe the current behavior

A keras model containing a tf.tile op layer with a tensor in the multiples arg throws an exception when saving to hdf5.

(I'm using tf.tile because RepeatVector(n) doesn't accept a tensor for n. The goal is to stack a 2d feature batch so it can be concatenated to a variable length 3d batch of sequence features.)

Describe the expected behavior

Model.save() should save the model.

Code to reproduce the issue

import numpy as np
import tensorflow as tf
from tensorflow.keras.layers import Input
from tensorflow.keras import Model

a = Input(shape=(10,))
out = tf.tile(a, (1, tf.shape(a)[0]))
model = Model(a, out)

x = np.zeros((50,10), dtype=np.float32)
print(model(x).numpy())

model.save('my_model.h5')

Other info / logs


ValueError Traceback (most recent call last)
in
11 print(model(x).numpy())
12
---> 13 model.save(model_dir + '/my_model.h5')

~/miniconda3/envs/tf20/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/network.py in save(self, filepath, overwrite, include_optimizer, save_format, signatures, options)
1187 """
1188 saving.save_model(self, filepath, overwrite, include_optimizer, save_format,
-> 1189 signatures, options)
1190
1191 def save_weights(self, filepath, overwrite=True, save_format=None):

~/miniconda3/envs/tf20/lib/python3.6/site-packages/tensorflow_core/python/keras/saving/save.py in save_model(model, filepath, overwrite, include_optimizer, save_format, signatures, options)
110 'or using save_weights.')
111 hdf5_format.save_model_to_hdf5(
--> 112 model, filepath, overwrite, include_optimizer)
113 else:
114 saved_model_save.save(model, filepath, overwrite, include_optimizer,

~/miniconda3/envs/tf20/lib/python3.6/site-packages/tensorflow_core/python/keras/saving/hdf5_format.py in save_model_to_hdf5(model, filepath, overwrite, include_optimizer)
107 model_weights_group = f.create_group('model_weights')
108 model_layers = model.layers
--> 109 save_weights_to_hdf5_group(model_weights_group, model_layers)
110
111 # TODO(b/128683857): Add integration tests between tf.keras and external

~/miniconda3/envs/tf20/lib/python3.6/site-packages/tensorflow_core/python/keras/saving/hdf5_format.py in save_weights_to_hdf5_group(f, layers)
623
624 for layer in layers:
--> 625 g = f.create_group(layer.name)
626 weights = _legacy_weights(layer)
627 weight_values = K.batch_get_value(weights)

~/miniconda3/envs/tf20/lib/python3.6/site-packages/h5py/_hl/group.py in create_group(self, name, track_order)
66 name, lcpl = self._e(name, lcpl=True)
67 gcpl = Group._gcpl_crt_order if track_order else None
---> 68 gid = h5g.create(self.id, name, lcpl=lcpl, gcpl=gcpl)
69 return Group(gid)
70

h5py/_objects.pyx in h5py._objects.with_phil.wrapper()

h5py/_objects.pyx in h5py._objects.with_phil.wrapper()

h5py/h5g.pyx in h5py.h5g.create()

ValueError: Unable to create group (name already exists)

Metadata

Metadata

Assignees

Labels

TF 2.0Issues relating to TensorFlow 2.0comp:kerasKeras related issuesstat:awaiting tensorflowerStatus - Awaiting response from tensorflowertype:bugBug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions