当我在运行“使用在 Vertex AI 上托管的 DNN 进行多类预测”的colab代码时,在运行如下代码块的时候
class DeSerializeInput(tf.keras.layers.Layer):
def init(self, **kwargs):
super().init(**kwargs)
def call(self, inputs_dict):
return {
k: tf.map_fn(lambda x: tf.io.parse_tensor(x, tf.float32),
tf.io.decode_base64(v),
fn_output_signature=tf.float32)
for (k, v) in inputs_dict.items()
}
def get_config(self):
config = super().get_config()
return config
class ReSerializeOutput(tf.keras.layers.Layer):
def init(self, **kwargs):
super().init(**kwargs)
def call(self, output_tensor):
return tf.map_fn(lambda x: tf.io.encode_base64(tf.io.serialize_tensor(x)),
output_tensor,
fn_output_signature=tf.string)
def get_config(self):
config = super().get_config()
return config
input_deserializer = DeSerializeInput()
output_deserializer = ReSerializeOutput()
serialized_inputs = {
b: tf.keras.Input(shape=[], dtype='string', name=b) for b in BANDS
}
updated_model_input = input_deserializer(serialized_inputs)
updated_model = wrapped_model(updated_model_input)
updated_model = output_deserializer(updated_model)
updated_model= tf.keras.Model(serialized_inputs, updated_model)
产生了如下错误
ValueError Traceback (most recent call last)
/tmp/ipython-input-81-3006780972.py in <cell line: 0>()
36 }
37
---> 38 updated_model_input = input_deserializer(serialized_inputs)
39 updated_model = wrapped_model(updated_model_input)
40 updated_model = output_deserializer(updated_model)
1 frames
/usr/local/lib/python3.11/dist-packages/optree/ops.py in tree_map(func, tree, is_leaf, none_is_leaf, namespace, *rests)
764 leaves, treespec = _C.flatten(tree, is_leaf, none_is_leaf, namespace)
765 flat_args = [leaves] + [treespec.flatten_up_to(r) for r in rests]
--> 766 return treespec.unflatten(map(func, *flat_args))
767
768
ValueError: Exception encountered when calling DeSerializeInput.call().
Could not automatically infer the output shape / dtype of 'de_serialize_input_32' (of type DeSerializeInput). Either the DeSerializeInput.call() method is incorrect, or you need to implement the DeSerializeInput.compute_output_spec() / compute_output_shape() method. Error encountered:
as_list() is not defined on an unknown TensorShape.
Arguments received by DeSerializeInput.call():
• args=({'SR_B2': '', 'SR_B3': '', 'SR_B4': '', 'SR_B5': '', 'SR_B6': '', 'SR_B7': ''},)
• kwargs=<class 'inspect._empty'>
请问发生了什么情况?
如何调试?
当我在运行“使用在 Vertex AI 上托管的 DNN 进行多类预测”的colab代码时,在运行如下代码块的时候
class DeSerializeInput(tf.keras.layers.Layer):
def init(self, **kwargs):
super().init(**kwargs)
def call(self, inputs_dict):
return {
k: tf.map_fn(lambda x: tf.io.parse_tensor(x, tf.float32),
tf.io.decode_base64(v),
fn_output_signature=tf.float32)
for (k, v) in inputs_dict.items()
}
def get_config(self):
config = super().get_config()
return config
class ReSerializeOutput(tf.keras.layers.Layer):
def init(self, **kwargs):
super().init(**kwargs)
def call(self, output_tensor):
return tf.map_fn(lambda x: tf.io.encode_base64(tf.io.serialize_tensor(x)),
output_tensor,
fn_output_signature=tf.string)
def get_config(self):
config = super().get_config()
return config
input_deserializer = DeSerializeInput()
output_deserializer = ReSerializeOutput()
serialized_inputs = {
b: tf.keras.Input(shape=[], dtype='string', name=b) for b in BANDS
}
updated_model_input = input_deserializer(serialized_inputs)
updated_model = wrapped_model(updated_model_input)
updated_model = output_deserializer(updated_model)
updated_model= tf.keras.Model(serialized_inputs, updated_model)
产生了如下错误
ValueError Traceback (most recent call last)
/tmp/ipython-input-81-3006780972.py in <cell line: 0>()
36 }
37
---> 38 updated_model_input = input_deserializer(serialized_inputs)
39 updated_model = wrapped_model(updated_model_input)
40 updated_model = output_deserializer(updated_model)
1 frames
/usr/local/lib/python3.11/dist-packages/optree/ops.py in tree_map(func, tree, is_leaf, none_is_leaf, namespace, *rests)
764 leaves, treespec = _C.flatten(tree, is_leaf, none_is_leaf, namespace)
765 flat_args = [leaves] + [treespec.flatten_up_to(r) for r in rests]
--> 766 return treespec.unflatten(map(func, *flat_args))
767
768
ValueError: Exception encountered when calling DeSerializeInput.call().
Could not automatically infer the output shape / dtype of 'de_serialize_input_32' (of type DeSerializeInput). Either the
DeSerializeInput.call()method is incorrect, or you need to implement theDeSerializeInput.compute_output_spec() / compute_output_shape()method. Error encountered:as_list() is not defined on an unknown TensorShape.
Arguments received by DeSerializeInput.call():
• args=({'SR_B2': '', 'SR_B3': '', 'SR_B4': '', 'SR_B5': '', 'SR_B6': '', 'SR_B7': ''},)
• kwargs=<class 'inspect._empty'>
请问发生了什么情况?
如何调试?