Python tf.string_split()错误

Python tf.string_split()错误,python,tensorflow,Python,Tensorflow,我使用的是python 3.7,tensorflow版本1.14.0 我试图使用tf.string\u split()从数据集的目录中获取类名 当我使用这种格式时 path1 = 'c:/users/path/to/directory/' def get_label(path): # convert the path to a list of path components # present path as vector parts = tf.string_split(

我使用的是python 3.7,tensorflow版本1.14.0

我试图使用
tf.string\u split()
从数据集的目录中获取类名

当我使用这种格式时

path1 = 'c:/users/path/to/directory/'
def get_label(path):
    # convert the path to a list of path components
    # present path as vector
    parts = tf.string_split([path], '/')
    # The 2nd to last is the class-directory
    return parts[-2] == CLASS_NAMES

get_label(path1)
我得到这个错误:

TypeError: 'SparseTensor' object is not subscriptable
InvalidArgumentError: input must be a vector, got shape: [] [Op:StringSplit]
如果我使用这种格式:

def get_label(path):
    # convert the path to a list of path components
    parts = tf.string_split(path, '/')
    # The 2nd to last is the class-directory
    return parts[-2] == CLASS_NAMES
get_label(path1)
我得到这个错误:

TypeError: 'SparseTensor' object is not subscriptable
InvalidArgumentError: input must be a vector, got shape: [] [Op:StringSplit]

我给了它一个向量,结果是不可分脚本的,我给了它一个形状,它不能分割它。我不确定还要尝试什么。

如果使用
tf.string\u split
,它将返回
SparseTensor
类型,该类型具有
索引
属性。我猜你想这么做

path1='c:/users/path/to/directory/'
def get_标签(路径):
#将路径转换为路径组件列表
#作为向量的当前路径
parts=tf.string_split([path],“/”)
#倒数第二个是类目录
返回tf.equal(部分值[-2],类名称)
eq\u t=获取标签(路径1)