def umap_funcx # 将输入转换为numpy数组 x = xnumpy # 使用UMAP进行降维 embedding = umapUMAPfit_transformx # 将输出转换为Tensor embedding = tfconvert_to_tensorembedding dtype=tffloat32 return embedding#
The error suggests that the UMAPLayer is expecting a tuple as input, but it is receiving a Tensor instead. This is likely because the UMAPLayer is expecting a tuple of inputs, but only receiving a single input Tensor.
To fix this, you can modify the call function in the UMAPLayer to take a tuple of inputs, and then pass the input Tensor as a single-element tuple to the py_function call:
class UMAPLayer(tf.keras.layers.Layer):
def __init__(self, **kwargs):
super(UMAPLayer, self).__init__(**kwargs)
def call(self, inputs):
# Ensure that inputs is a tuple
if not isinstance(inputs, tuple):
inputs = (inputs,)
# Use tf.py_function to call umap_func with the inputs
embedding = tf.py_function(umap_func, inputs, tf.float32)
# Return the embedding Tensor
return embedding
This should allow the UMAPLayer to properly receive a tuple of inputs and pass them to the umap_func function.
原文地址: https://www.cveoy.top/t/topic/bK65 著作权归作者所有。请勿转载和采集!