Tensorflow &引用;Conv2D op目前仅支持CPU上的NHWC张量格式;尽管NHWC格式(YOLO 3)存在错误
为了学习如何使用Tensorflow 2和YOLO框架,我正在尝试从中运行一些示例代码。我的笔记本电脑有一个M1000M图形卡,我从NVIDIA安装了CUDA平台 因此,所讨论的代码是这一位:Tensorflow &引用;Conv2D op目前仅支持CPU上的NHWC张量格式;尽管NHWC格式(YOLO 3)存在错误,tensorflow,keras,tensorflow2.0,yolo,Tensorflow,Keras,Tensorflow2.0,Yolo,为了学习如何使用Tensorflow 2和YOLO框架,我正在尝试从中运行一些示例代码。我的笔记本电脑有一个M1000M图形卡,我从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, io
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}}]]
完整日志请参阅
如果我理解正确的话,inputs=tf.compat.v1.placeholder(tf.float32,[batch\u size,*\u MODEL\u size,3])
的格式已经是NHWC(MODEL size是一个由2个数字组成的元组),我不知道我需要如何在代码中进行更改才能在CPU上运行
如果我理解正确,输入的格式=
占位符(tf.float32,[batch\u size,*\u MODEL\u size,3])是
已经是NHWC(型号大小是2个数字的元组),我不知道怎么做
我需要更改代码中的内容,以使其在CPU上运行
是的,你是。但是:
后来:
def __call__(self, inputs, training):
"""Add operations to detect boxes for a batch of input images.
Args:
inputs: A Tensor representing a batch of input images.
training: A boolean, whether to use in training or inference mode.
Returns:
A list containing class-to-boxes dictionaries
for each sample in the batch.
"""
with tf.compat.v1.variable_scope('yolo_v3_model'):
if self.data_format == 'channels_first':
inputs = tf.transpose(inputs, [0, 3, 1, 2])
解决方案:
model=Yolo\u v3(n\u classes=n\u classes,model\u size=\u model\u size,
max\u output\u size=\u max\u output\u size,
iou\u threshold=iou\u threshold,
置信度阈值=置信度阈值,
data\u format='channels\u last')
我回答了你的问题了吗?还是有什么不清楚的地方?很难说。问题是,我太笨了,无法在Cuda安装后针对这个特定问题重新启动。然而,我最终使用conda而不是pip来安装依赖项,因为这会自动拉取所有cuda依赖项
def __call__(self, inputs, training):
"""Add operations to detect boxes for a batch of input images.
Args:
inputs: A Tensor representing a batch of input images.
training: A boolean, whether to use in training or inference mode.
Returns:
A list containing class-to-boxes dictionaries
for each sample in the batch.
"""
with tf.compat.v1.variable_scope('yolo_v3_model'):
if self.data_format == 'channels_first':
inputs = tf.transpose(inputs, [0, 3, 1, 2])