【发布时间】:2020-12-18 16:56:14
【问题描述】:
我正在尝试从github 运行一些示例代码,以学习使用 Tensorflow 2 和 YOLO 框架。我的笔记本电脑有一个 M1000M 显卡,我从here 安装了 NVIDIA 的 CUDA 平台。
所以有问题的代码是这样的:
tf.compat.v1.disable_eager_execution()
_MODEL_SIZE = (416, 416)
_CLASS_NAMES_FILE = './data/labels/coco.names'
_MAX_OUTPUT_SIZE = 20
def main(type, iou_threshold, confidence_threshold, input_names):
class_names = load_class_names(_CLASS_NAMES_FILE)
n_classes = len(class_names)
model = Yolo_v3(n_classes=n_classes, model_size=_MODEL_SIZE,
max_output_size=_MAX_OUTPUT_SIZE,
iou_threshold=iou_threshold,
confidence_threshold=confidence_threshold)
if type == 'images':
batch_size = len(input_names)
batch = load_images(input_names, model_size=_MODEL_SIZE)
inputs = tf.compat.v1.placeholder(tf.float32, [batch_size, *_MODEL_SIZE, 3])
detections = model(inputs, training=False)
saver = tf.compat.v1.train.Saver(tf.compat.v1.global_variables(scope='yolo_v3_model'))
with tf.compat.v1.Session() as sess:
saver.restore(sess, './weights/model.ckpt')
detection_result = sess.run(detections, feed_dict={inputs: batch})
draw_boxes(input_names, detection_result, class_names, _MODEL_SIZE)
print('Detections have been saved successfully.')
在执行此操作时(也想知道为什么首先启动 detection.py 不使用 GPU),我收到错误消息:
File "C:\SDKs etc\Python 3.8\lib\site-packages\tensorflow\python\client\session.py", line 1451, in _call_tf_sessionrun
return tf_session.TF_SessionRun_wrapper(self._session, options, feed_dict,
tensorflow.python.framework.errors_impl.UnimplementedError: The Conv2D op currently only supports the NHWC tensor format on the CPU. The op was given the format: NCHW
[[{{node yolo_v3_model/conv2d/Conv2D}}]]
完整日志见here。
如果我理解正确,inputs = tf.compat.v1.placeholder(tf.float32, [batch_size, *_MODEL_SIZE, 3]) 的格式已经是 NHWC(模型大小是 2 个数字的元组),我不知道我需要如何更改代码中的内容才能使其在 CPU 上运行。
【问题讨论】:
-
我回答了你的问题还是有什么不清楚的地方?
-
很难说。问题是我太笨了,在安装 Cuda 后无法重新启动这个特定问题。但是,我最终使用 conda 而不是 pip 来安装我的依赖项,因为这会自动拉取所有 cuda 依赖项
标签: tensorflow keras tensorflow2.0 yolo