attributeError:'张量'对象没有属性' numpy'通过我的数据集映射功能
我正在尝试将函数process_image
映射到数据集。此功能调用另一个函数,get_label
。在get_label
中,我正在尝试从图像中检索标签的名称。
文件路径就是这样:c:\\ users \\ sis \\ desktop \\ test \\ 0002_c1s1_000451_03.jpg
。该标签为编号0002
。
def get_lab(file_path):
parts = tf.strings.split(file_path, os.path.sep)
part=parts[-1].numpy().decode().split('_')[0]
label=tf.strings.to_number(part)
return label
I'm trying to map a function process_image
to the dataset. This function calls another function, get_label
. In get_label
, I'm trying to retrieve the label's name from images.
The file path is like this: C:\\Users\\sis\\Desktop\\test\\0002_c1s1_000451_03.jpg
. The label is number 0002
.
def get_lab(file_path):
parts = tf.strings.split(file_path, os.path.sep)
part=parts[-1].numpy().decode().split('_')[0]
label=tf.strings.to_number(part)
return label
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我解决了!我不明白错误的位置,我认为上一个代码混合的急切模式和图形模式,因此我更改了
get_label
函数的代码,并且可以使用!I solved it! I didn't understand exactly where the error was, I think the previous code mixed eager mode and graph mode, so I changed the code of
get_label
function and it worked!您可以应用于创建用于外部程序的足够的文件夹名称。
[示例]:
[输出]:
You may applied to folder name that create sufficeints used of external programs.
[ Sample ]:
[ Output ]: