无法使用 save/pickle 保存 tensorrflow keras 量子模型
cannot save tensorrflow keras quantum model using save/pickle
如何保存tensorflow量子模型?当我试图用量子电路保存 keras 模型时,我得到以下信息。
我没有找到任何支持。
tensorflow:Layer add_circuit_2 传递了不可序列化的关键字参数
tensorflow:Layer add_circuit_2 传递了不可序列化的关键字参数
tensorflow:Layer add_circuit_2 传递了不可序列化的关键字参数
WARNING:tensorflow:Layer add_circuit_2 was passed non-serializable keyword arguments: {'prepend':
cirq.Circuit([
cirq.Moment(operations=[
cirq.H.on(cirq.GridQubit(0, 0)),
cirq.H.on(cirq.GridQubit(0, 1)),
cirq.H.on(cirq.GridQubit(0, 2)),
cirq.H.on(cirq.GridQubit(0, 3)),
cirq.H.on(cirq.GridQubit(1, 0)),
cirq.H.on(cirq.GridQubit(1, 1)),
cirq.H.on(cirq.GridQubit(1, 2)),
cirq.H.on(cirq.GridQubit(1, 3)),
cirq.H.on(cirq.GridQubit(2, 0)),
cirq.H.on(cirq.GridQubit(2, 1)),
cirq.H.on(cirq.GridQubit(2, 2)),
cirq.H.on(cirq.GridQubit(2, 3)),
cirq.H.on(cirq.GridQubit(3, 0)),
cirq.H.on(cirq.GridQubit(3, 1)),
cirq.H.on(cirq.GridQubit(3, 2)),
cirq.H.on(cirq.GridQubit(3, 3)),
]),
cirq.Moment(operations=[
cirq.CZ.on(cirq.GridQubit(0, 0), cirq.GridQubit(0, 1)),
]),
cirq.Moment(operations=[
cirq.CZ.on(cirq.GridQubit(0, 1), cirq.GridQubit(0, 2)),
]),
cirq.Moment(operations=[
cirq.CZ.on(cirq.GridQubit(0, 2), cirq.GridQubit(0, 3)),
]),
cirq.Moment(operations=[
cirq.CZ.on(cirq.GridQubit(0, 3), cirq.GridQubit(1, 0)),
]),
cirq.Moment(operations=[
cirq.CZ.on(cirq.GridQubit(1, 0), cirq.GridQubit(1, 1)),
]),
cirq.Moment(operations=[
cirq.CZ.on(cirq.GridQubit(1, 1), cirq.GridQubit(1, 2)),
]),
cirq.Moment(operations=[
cirq.CZ.on(cirq.GridQubit(1, 2), cirq.GridQubit(1, 3)),
]),
cirq.Moment(operations=[
cirq.CZ.on(cirq.GridQubit(1, 3), cirq.GridQubit(2, 0)),
]),
cirq.Moment(operations=[
cirq.CZ.on(cirq.GridQubit(2, 0), cirq.GridQubit(2, 1)),
]),
cirq.Moment(operations=[
cirq.CZ.on(cirq.GridQubit(2, 1), cirq.GridQubit(2, 2)),
]),
cirq.Moment(operations=[
cirq.CZ.on(cirq.GridQubit(2, 2), cirq.GridQubit(2, 3)),
]),
cirq.Moment(operations=[
cirq.CZ.on(cirq.GridQubit(2, 3), cirq.GridQubit(3, 0)),
]),
cirq.Moment(operations=[
cirq.CZ.on(cirq.GridQubit(3, 0), cirq.GridQubit(3, 1)),
]),
cirq.Moment(operations=[
cirq.CZ.on(cirq.GridQubit(3, 1), cirq.GridQubit(3, 2)),
]),
cirq.Moment(operations=[
cirq.CZ.on(cirq.GridQubit(3, 2), cirq.GridQubit(3, 3)),
]),
cirq.Moment(operations=[
cirq.CZ.on(cirq.GridQubit(3, 3), cirq.GridQubit(0, 0)),
]),])}.
They will not be included in the serialized model (and thus will be missing at deserialization time).
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
<ipython-input-91-a74ee5c9d34d> in <module>()
----> 1 qcnn_model.save('qcnn_model.h5')
8 frames
/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/keras/engine/base_layer.py in
get_config(self)
497 # or that `get_config` has been overridden:
498 if len(extra_args) > 1 and hasattr(self.get_config, '_is_default'):
--> 499 raise NotImplementedError('Layers with arguments in `__init__` must '
500 'override `get_config`.')
501 return config
NotImplementedError: Layers with arguments in `__init__` must override `get_config`.
TensorFlow Quantum 尚未实现 get_config
和 load_config
。我们在保存某些 Cirq 对象时遇到了一些困难,我们正在解决这个问题。
现在,如果您想保存包含量子层的模型,您可以使用
model = tf.keras.Model(...)
model.save_weights("some_path")
...
model.load_weights("some_path")
改为函数。
如何保存tensorflow量子模型?当我试图用量子电路保存 keras 模型时,我得到以下信息。 我没有找到任何支持。 tensorflow:Layer add_circuit_2 传递了不可序列化的关键字参数 tensorflow:Layer add_circuit_2 传递了不可序列化的关键字参数 tensorflow:Layer add_circuit_2 传递了不可序列化的关键字参数
WARNING:tensorflow:Layer add_circuit_2 was passed non-serializable keyword arguments: {'prepend':
cirq.Circuit([
cirq.Moment(operations=[
cirq.H.on(cirq.GridQubit(0, 0)),
cirq.H.on(cirq.GridQubit(0, 1)),
cirq.H.on(cirq.GridQubit(0, 2)),
cirq.H.on(cirq.GridQubit(0, 3)),
cirq.H.on(cirq.GridQubit(1, 0)),
cirq.H.on(cirq.GridQubit(1, 1)),
cirq.H.on(cirq.GridQubit(1, 2)),
cirq.H.on(cirq.GridQubit(1, 3)),
cirq.H.on(cirq.GridQubit(2, 0)),
cirq.H.on(cirq.GridQubit(2, 1)),
cirq.H.on(cirq.GridQubit(2, 2)),
cirq.H.on(cirq.GridQubit(2, 3)),
cirq.H.on(cirq.GridQubit(3, 0)),
cirq.H.on(cirq.GridQubit(3, 1)),
cirq.H.on(cirq.GridQubit(3, 2)),
cirq.H.on(cirq.GridQubit(3, 3)),
]),
cirq.Moment(operations=[
cirq.CZ.on(cirq.GridQubit(0, 0), cirq.GridQubit(0, 1)),
]),
cirq.Moment(operations=[
cirq.CZ.on(cirq.GridQubit(0, 1), cirq.GridQubit(0, 2)),
]),
cirq.Moment(operations=[
cirq.CZ.on(cirq.GridQubit(0, 2), cirq.GridQubit(0, 3)),
]),
cirq.Moment(operations=[
cirq.CZ.on(cirq.GridQubit(0, 3), cirq.GridQubit(1, 0)),
]),
cirq.Moment(operations=[
cirq.CZ.on(cirq.GridQubit(1, 0), cirq.GridQubit(1, 1)),
]),
cirq.Moment(operations=[
cirq.CZ.on(cirq.GridQubit(1, 1), cirq.GridQubit(1, 2)),
]),
cirq.Moment(operations=[
cirq.CZ.on(cirq.GridQubit(1, 2), cirq.GridQubit(1, 3)),
]),
cirq.Moment(operations=[
cirq.CZ.on(cirq.GridQubit(1, 3), cirq.GridQubit(2, 0)),
]),
cirq.Moment(operations=[
cirq.CZ.on(cirq.GridQubit(2, 0), cirq.GridQubit(2, 1)),
]),
cirq.Moment(operations=[
cirq.CZ.on(cirq.GridQubit(2, 1), cirq.GridQubit(2, 2)),
]),
cirq.Moment(operations=[
cirq.CZ.on(cirq.GridQubit(2, 2), cirq.GridQubit(2, 3)),
]),
cirq.Moment(operations=[
cirq.CZ.on(cirq.GridQubit(2, 3), cirq.GridQubit(3, 0)),
]),
cirq.Moment(operations=[
cirq.CZ.on(cirq.GridQubit(3, 0), cirq.GridQubit(3, 1)),
]),
cirq.Moment(operations=[
cirq.CZ.on(cirq.GridQubit(3, 1), cirq.GridQubit(3, 2)),
]),
cirq.Moment(operations=[
cirq.CZ.on(cirq.GridQubit(3, 2), cirq.GridQubit(3, 3)),
]),
cirq.Moment(operations=[
cirq.CZ.on(cirq.GridQubit(3, 3), cirq.GridQubit(0, 0)),
]),])}.
They will not be included in the serialized model (and thus will be missing at deserialization time).
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
<ipython-input-91-a74ee5c9d34d> in <module>()
----> 1 qcnn_model.save('qcnn_model.h5')
8 frames
/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/keras/engine/base_layer.py in
get_config(self)
497 # or that `get_config` has been overridden:
498 if len(extra_args) > 1 and hasattr(self.get_config, '_is_default'):
--> 499 raise NotImplementedError('Layers with arguments in `__init__` must '
500 'override `get_config`.')
501 return config
NotImplementedError: Layers with arguments in `__init__` must override `get_config`.
TensorFlow Quantum 尚未实现 get_config
和 load_config
。我们在保存某些 Cirq 对象时遇到了一些困难,我们正在解决这个问题。
现在,如果您想保存包含量子层的模型,您可以使用
model = tf.keras.Model(...)
model.save_weights("some_path")
...
model.load_weights("some_path")
改为函数。