Issue 1:
System information.

Have I written custom code (as opposed to using a stock example script provided in Keras):

OS Platform and Distribution (e.g., Linux Ubuntu 16.04):

TensorFlow installed from (source or binary):

TensorFlow version (use command below): 2.4.1, 2.6.4

Python version:

Bazel version (if compiling from source):

GPU model and memory:

Exact command to reproduce:

Describe the problem.

I want to build sinmple model which consist of different version of same model, here which is efficient-net. The model build successfully. The training also works fine. But until now, I would get the following error if I use ModelCheckpoint to save model in the runtime.

RuntimeError: Unable to create link (name already exists)

To solve this, one of (dirty) workaround (suggestion get from web) is to rename weight variable. But that raise another issue at the time of model saving due to unexpected suffix with variable name.

/opt/conda/lib/python3.7/site-packages/tensorflow/python/ops/resource_variable_ops.py in write_object_proto_for_resource_variable(resource_variable, proto, options)

2319 raise ValueError("Cowardly refusing to save variable {} because of"

2320 " unexpected suffix which won't be restored.".format(

-> 2321 resource_variable.name))

2322 proto.variable.name = meta_graph._op_name(resource_variable.name) # pylint: disable=protected-access

2323 proto.variable.trainable = resource_variable.trainable

ValueError: Cowardly refusing to save
variable normalization/mean:00 because of unexpected suffix which won't be restored.

Standalone code to reproduce the issue.

Here is the code to reproduce.

from tensorflow.keras.applications import (
EfficientNetB0, EfficientNetB1, EfficientNetB2
)
image_sizes_maps = {
'B0': [EfficientNetB0, 224],
'B1': [EfficientNetB1, 240],
'B2': [EfficientNetB2, 260],
}

def get_model():
base_embeds = []
model_input = tf.keras.Input(shape=(None, None, 3),name='effnets')

for key,value in image_sizes_maps.items():
base_model, image_size = value
x = tf.image.resize(model_input, [image_size, image_size], name=f'resize_{key}')
z = base_model(
include_top=False,
)(x)
base_embeds.append(z)

model = tf.keras.Model(model_input, base_embeds)
return model

MODEL = get_model()

# DIRTY SOLUTION
# IF WE DON'T DO IT, THEN IT WILL CAUSE
# Unable to create link (name already exists)
for i in range(len(MODEL.weights)):
MODEL.weights[i]._handle_name = MODEL.weights[i].name + str(i)

MODEL.save("model")

2022-09-04 21:11:19.660403: W tensorflow/python/util/util.cc:348] Sets are not currently considered sequences, but this may change in the future, so consider avoiding using them.
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/tmp/ipykernel_17/3402985690.py in <module>
----> 1 MODEL.save("E0_E6")

ValueError: Cowardly refusing to save
variable normalization/mean:00 because of unexpected suffix which won't be restored.

Additional Content

With this, you can check if there is duplicate variable name.

from collections import Counter

def non_unique(l):
def low(x):
return x.lower() if isinstance(x, str) else x
c = Counter(map(low, l))
return [x for x in l if c[low(x)] > 1]

hold_w = []
for i, w in enumerate(MODEL.weights):
hold_w.append(w.name)

# It will return empty if all variable names are unique.
non_unique(hold_w)

Issue 2:
I am not very clear about the timesteps in the input of RNN and LSTM. In my understanding, if we set timesteps as K, Keras will look back for K steps (So, the RNN or LSTM will be unrolled for K times) and make the prediction. Is it correct?

Also, How does LSTM in Keras unroll itself? Which parameter decides the length of TruncatedBPTT? Thanks