I tried the example of Titanic Survival Prediction from your document and export the model with the following code ,although the model is exported I got numpy error.
model = clf.export_model()
model.save('titanic.h5')
Traceback (most recent call last):
File "titanic.py", line 17, in <module>
model.save('titanic.h5')
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\keras\engine\network.py", line 1008, in save
signatures, options)
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\keras\saving\save.py", line 112, in save_model
model, filepath, overwrite, include_optimizer)
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\keras\saving\hdf5_format.py", line 109, in save_model_to_hdf5
save_weights_to_hdf5_group(model_weights_group, model_layers)
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\keras\saving\hdf5_format.py", line 627, in save_weights_to_hdf5_group
weight_values = K.batch_get_value(weights)
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\keras\backend.py", line 3270, in batch_get_value
return [x.numpy() for x in tensors]
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\keras\backend.py", line 3270, in <listcomp>
return [x.numpy() for x in tensors]
AttributeError: 'TrackableWeightHandler' object has no attribute 'numpy'
When I was trying to load the HDF5 model for prediction , errors occurs
model = tf.keras.models.load_model('titanic.h5', custom_objects=ak.CUSTOM_OBJECTS)
Traceback (most recent call last):
File "load_model.py", line 4, in <module>
model = tf.keras.models.load_model('titanic.h5', custom_objects=ak.CUSTOM_OBJECTS)
File "C:\Users\Python\Python37\lib\site-packages\tensorflow_core\python\keras\saving\save.py", line 146, in load_model
return hdf5_format.load_model_from_hdf5(filepath, custom_objects, compile)
File "C:\Users\Python\Python37\lib\site-packages\tensorflow_core\python\keras\saving\hdf5_format.py", line 171, in load_model_from_hdf5
load_weights_from_hdf5_group(f['model_weights'], model.layers)
File "C:\Users\Python\Python37\lib\site-packages\tensorflow_core\python\keras\saving\hdf5_format.py", line 668, in load_weights_from_hdf5_group
g = f[name]
File "h5py\_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
File "h5py\_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
File "C:\Users\Python\Python37\lib\site-packages\h5py\_hl\group.py", line 264, in __getitem__
oid = h5o.open(self.id, self._e(name), lapl=self._lapl)
File "h5py\_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
File "h5py\_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
File "h5py\h5o.pyx", line 190, in h5py.h5o.open
KeyError: "Unable to open object (object 'dense' doesn't exist)"
same error
error ifo
File "/home/dy/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/keras/utils/generic_utils.py", line 250, in class_and_config_for_serialized_keras_object
raise ValueError('Unknown ' + printable_module_name + ': ' + class_name)
ValueError: Unknown layer: Normalization
here is my code
model = tf.keras.models.load_model(self.local_path+'model.h5',custom_objects=ak.CUSTOM_OBJECTS)
Hi, Would you try the latest tf-nightly? It may resolve the issue. Thanks
Hi, unfortunately the latest tf-nightly raises another error:
AttributeError: in user code:
/home/user/tf-nightly-test/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py:499 train_function *
outputs = self.distribute_strategy.experimental_run_v2(
/home/user/tf-nightly-test/lib/python3.6/site-packages/tensorflow/python/distribute/distribute_lib.py:856 experimental_run_v2 **
return self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs)
/home/user/tf-nightly-test/lib/python3.6/site-packages/tensorflow/python/distribute/distribute_lib.py:2112 call_for_each_replica
return self._call_for_each_replica(fn, args, kwargs)
/home/user/tf-nightly-test/lib/python3.6/site-packages/tensorflow/python/distribute/distribute_lib.py:2470 _call_for_each_replica
return fn(*args, **kwargs)
/home/user/tf-nightly-test/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py:471 train_step **
self.compiled_metrics.update_state(y, y_pred, sample_weight)
/home/user/tf-nightly-test/lib/python3.6/site-packages/tensorflow/python/keras/engine/compile_utils.py:348 update_state
self._build(y_pred, y_true)
/home/user/tf-nightly-test/lib/python3.6/site-packages/tensorflow/python/keras/engine/compile_utils.py:267 _build
self._metrics, y_true, y_pred)
/home/user/tf-nightly-test/lib/python3.6/site-packages/tensorflow/python/util/nest.py:1118 map_structure_up_to
**kwargs)
/home/user/tf-nightly-test/lib/python3.6/site-packages/tensorflow/python/util/nest.py:1214 map_structure_with_tuple_paths_up_to
*flat_value_lists)]
/home/user/tf-nightly-test/lib/python3.6/site-packages/tensorflow/python/util/nest.py:1213 <listcomp>
results = [func(*args, **kwargs) for args in zip(flat_path_list,
/home/user/tf-nightly-test/lib/python3.6/site-packages/tensorflow/python/util/nest.py:1116 <lambda>
lambda _, *values: func(*values), # Discards the path arg.
/home/user/tf-nightly-test/lib/python3.6/site-packages/tensorflow/python/keras/engine/compile_utils.py:377 _get_metric_objects
return [self._get_metric_object(m, y_t, y_p) for m in metrics]
/home/user/tf-nightly-test/lib/python3.6/site-packages/tensorflow/python/keras/engine/compile_utils.py:377 <listcomp>
return [self._get_metric_object(m, y_t, y_p) for m in metrics]
/home/user/tf-nightly-test/lib/python3.6/site-packages/tensorflow/python/keras/engine/compile_utils.py:398 _get_metric_object
y_t_rank = len(y_t.shape.as_list())
AttributeError: 'tuple' object has no attribute 'shape'
Within TF==2.1.0 I used pandas Dataframes as Input and everything worked fine except for saving the model after calling best_model = model.export_model(). Now I transformed these Dataframes into Numpy arrays but the error mentioned above occurs.
any news ?
I have tested all dev versions of tf-nightly-gpu==2.2.0 in colab including the latest version(tf-nightly-gpu 2.2.0.dev20200308) , error still exits.
From tf-nightly-gpu==2.2.0.dev20200226 to the latest version(tf-nightly-gpu 2.2.0.dev20200308), it will raise AttributeError: 'tuple' object has no attribute 'shape' error:
````
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:493 train_function *
outputs = self.distribute_strategy.experimental_run_v2(
/usr/local/lib/python3.6/dist-packages/tensorflow/python/distribute/distribute_lib.py:856 experimental_run_v2 *
return self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/distribute/distribute_lib.py:2112 call_for_each_replica
return self._call_for_each_replica(fn, args, kwargs)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/distribute/distribute_lib.py:2470 _call_for_each_replica
return fn(args, *kwargs)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:465 _train_step *
self.compiled_metrics.update_state(y, y_pred, sample_weight)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/compile_utils.py:348 update_state
self._build(y_pred, y_true)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/compile_utils.py:267 _build
self._metrics, y_true, y_pred)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/util/nest.py:1118 map_structure_up_to
*kwargs)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/util/nest.py:1214 map_structure_with_tuple_paths_up_to
*flat_value_lists)]
/usr/local/lib/python3.6/dist-packages/tensorflow/python/util/nest.py:1213
results = [func(
/usr/local/lib/python3.6/dist-packages/tensorflow/python/util/nest.py:1116
lambda _, *values: func(
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/compile_utils.py:377 _get_metric_objects
return [self._get_metric_object(m, y_t, y_p) for m in metrics]
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/compile_utils.py:377
return [self._get_metric_object(m, y_t, y_p) for m in metrics]
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/compile_utils.py:398 _get_metric_object
y_t_rank = len(y_t.shape.as_list())
AttributeError: 'tuple' object has no attribute 'shape'
With tf-nightly-gpu==2.2.0.dev20200218 and before, it will raise AttributeError: 'TrackableWeightHandler' object has no attribute 'numpy' error:
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/network.py in save(self, filepath, overwrite, include_optimizer, save_format, signatures, options)
1002 """
1003 save.save_model(self, filepath, overwrite, include_optimizer, save_format,
-> 1004 signatures, options)
1005
1006 def save_weights(self, filepath, overwrite=True, save_format=None):
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/saving/save.py in save_model(model, filepath, overwrite, include_optimizer, save_format, signatures, options)
133 'or using save_weights.')
134 hdf5_format.save_model_to_hdf5(
--> 135 model, filepath, overwrite, include_optimizer)
136 else:
137 saved_model_save.save(model, filepath, overwrite, include_optimizer,
/usr/local/lib/python3.6/dist-packages/tensorflow/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
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/saving/hdf5_format.py in save_weights_to_hdf5_group(f, layers)
627 g = f.create_group(layer.name)
628 weights = _legacy_weights(layer)
--> 629 weight_values = K.batch_get_value(weights)
630 weight_names = [w.name.encode('utf8') for w in weights]
631 save_attributes_to_hdf5_group(g, 'weight_names', weight_names)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/backend.py in batch_get_value(tensors)
3325 """
3326 if context.executing_eagerly():
-> 3327 return [x.numpy() for x in tensors]
3328 elif ops.inside_function(): # pylint: disable=protected-access
3329 raise RuntimeError('Cannot get value inside Tensorflow graph function.')
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/backend.py in
3325 """
3326 if context.executing_eagerly():
-> 3327 return [x.numpy() for x in tensors]
3328 elif ops.inside_function(): # pylint: disable=protected-access
3329 raise RuntimeError('Cannot get value inside Tensorflow graph function.')
AttributeError: 'TrackableWeightHandler' object has no attribute 'numpy'
````
I also found the latest tf-nightly doesn't solve the issue. We will need to further investigate it. Thanks
Hello,
Is there any update regarding this topic?
I find myself in the same situation...
Thanks!
(tf 2.1)
Whats the status on this? Not being able to load a saved model kind of defeats the purpose of autokeras in the first place...
As I tested, it works now with AutoKeras 1.0.3.
Thank you, it's working fine now.
As I tested, it works now with AutoKeras 1.0.3.
I'm getting the same error while loading the model:
WARNING:tensorflow:Error in loading the saved optimizer state. As a result, your model is starting with a freshly initialized optimizer.
and after model.fit(x_train, y_train, epoch=20)
I'm getting the following error:
`ValueError: in user code:
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:571 train_function *
outputs = self.distribute_strategy.run(
/usr/local/lib/python3.6/dist-packages/tensorflow/python/distribute/distribute_lib.py:951 run **
return self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/distribute/distribute_lib.py:2290 call_for_each_replica
return self._call_for_each_replica(fn, args, kwargs)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/distribute/distribute_lib.py:2649 _call_for_each_replica
return fn(*args, **kwargs)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:533 train_step **
y, y_pred, sample_weight, regularization_losses=self.losses)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/compile_utils.py:205 __call__
loss_value = loss_obj(y_t, y_p, sample_weight=sw)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/losses.py:143 __call__
losses = self.call(y_true, y_pred)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/losses.py:246 call
return self.fn(y_true, y_pred, **self._fn_kwargs)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/losses.py:1527 categorical_crossentropy
return K.categorical_crossentropy(y_true, y_pred, from_logits=from_logits)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/backend.py:4561 categorical_crossentropy
target.shape.assert_is_compatible_with(output.shape)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/tensor_shape.py:1117 assert_is_compatible_with
raise ValueError("Shapes %s and %s are incompatible" % (self, other))
ValueError: Shapes (None, 1) and (None, 10) are incompatible`
I think it mainly because of the categorical encoding? would you paste your code?
Most helpful comment
Hello,
Is there any update regarding this topic?
I find myself in the same situation...
Thanks!
(tf 2.1)