python - 如何在多线程/多处理时将 TensorFlow 张量转换为 tf.Dataset.map() 中的 NumPy 数组?
问题描述
我在 Eager Execution 中使用 TensorFlow 1.12。我有一个计算量很大的函数,我使用tf.Dataset.map()
. 在这个函数内部——我通过在急切执行中简单地对数据集进行 for 循环开发——我使用EagerTensor.numpy()
. 由于预处理我的数据集花费的时间太长,我现在希望对整个地图过程进行多线程处理,使用tf.Dataset.map(myfunction, num_cores=30)
. 但是,现在myfunction()
不再急切地执行了。myfunction()
我尝试了两件事:1)使用包装tf.py_function
,在这种情况下map()
不再是多线程的,2)打开tf.Session
内部并使用而不是myfunction()
获取我的NumPy数组,在这种情况下我需要提供输入张量(我不明白为什么):.eval()
.numpy()
InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'arg0' with dtype string
[[node arg0 (defined at /home/.../semantic_fpn.py:101) = Placeholder[dtype=DT_STRING, shape=<unknown>]]```
Is there an easy why for me to loop over my dataset with ```myfunction()``` (and its NumPy conversion) while multithreading/multiprocessing? I had additionally considered using a for-loop instead of ```.map()```, but I wouldn't know how to alter/write to records in a ```tf.Dataset```.
解决方案
推荐阅读
- javascript - 如何以角度在 NgFor 中获取下拉数据?
- python - discord.py 重写 - 如何检查 discord.Member 是否是机器人
- python - 从剪贴板读取二进制数据
- html - HTML/CSS 在表格中获取按钮和文本以及其他格式的正确顺序
- vue.js - 如何让 SPA 导航与使用 innerHTML 作为内容的外部框架一起工作
- mysql - 查询返回关于列的错误信息
- java - 如何为 KTable 多对一进行 leftJoin?
- javascript - ReactJs / Typescript:如何扩展状态接口
- phpmyadmin - phpmyadmin “templates/”目录不存在
- python - 弧线中的不同颜色