dragen1860 / TensorFlow-2.x-Tutorials

TensorFlow 2.x version's Tutorials and Examples, including CNN, RNN, GAN, Auto-Encoders, FasterRCNN, GPT, BERT examples, etc. TF 2.0版入门实例代码,实战教程。
6.38k stars 2.23k forks source link

如何判断训练数据是有效的 #52

Closed ainilian closed 4 years ago

ainilian commented 4 years ago

python train_model.py 报错内容: InvalidArgumentError Traceback (most recent call last)

in () 7 # dummpy forward to build network variables 8 # print("batch_imgs {}, batch_metas {}".format(batch_imgs, batch_metas)) ----> 9 _ = model((batch_imgs, batch_metas), training=False) ~/software/anaconda3/envs/tf2/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/base_layer.py in __call__(self, inputs, *args, **kwargs) 820 with base_layer_utils.autocast_context_manager( 821 self._compute_dtype): --> 822 outputs = self.call(cast_inputs, *args, **kwargs) 823 self._handle_activity_regularization(inputs, outputs) 824 self._set_mask_metadata(inputs, outputs, input_masks) fasterRCNN/detection/models/detectors/faster_rcnn.py in call(self, inputs, training) 156 print("fasterRcnn rcnn_probs_list {}, rcnn_deltas_list {}, rois_list {}, img_metas {}".format(rcnn_probs_list, rcnn_deltas_list, rois_list, img_metas)) 157 detections_list = self.bbox_head.get_bboxes( --> 158 rcnn_probs_list, rcnn_deltas_list, rois_list, img_metas) 159 160 return detections_list fasterRCNN/detection/models/bbox_heads/bbox_head.py in get_bboxes(self, rcnn_probs_list, rcnn_deltas_list, rois_list, img_metas) 120 self._get_bboxes_single( 121 rcnn_probs_list[i], rcnn_deltas_list[i], rois_list[i], pad_shapes[i]) --> 122 for i in range(img_metas.shape[0]) 123 ] 124 return detections_list fasterRCNN/detection/models/bbox_heads/bbox_head.py in (.0) 120 self._get_bboxes_single( 121 rcnn_probs_list[i], rcnn_deltas_list[i], rois_list[i], pad_shapes[i]) --> 122 for i in range(img_metas.shape[0]) 123 ] 124 return detections_list fasterRCNN/detection/models/bbox_heads/bbox_head.py in _get_bboxes_single(self, rcnn_probs, rcnn_deltas, rois, img_shape) 202 203 print("nms_kepp {}".format(nms_keep)) --> 204 nms_keep = tf.concat(nms_keep, axis=0) 205 206 # 3. Compute intersection between keep and nms_keep ~/software/anaconda3/envs/tf2/lib/python3.6/site-packages/tensorflow_core/python/util/dispatch.py in wrapper(*args, **kwargs) 178 """Call target, and fall back on dispatchers if there is a TypeError.""" 179 try: --> 180 return target(*args, **kwargs) 181 except (TypeError, ValueError): 182 # Note: convert_to_eager_tensor currently raises a ValueError, not a ~/software/anaconda3/envs/tf2/lib/python3.6/site-packages/tensorflow_core/python/ops/array_ops.py in concat(values, axis, name) 1515 dtype=dtypes.int32).get_shape().assert_has_rank(0) 1516 return identity(values[0], name=name) -> 1517 return gen_array_ops.concat_v2(values=values, axis=axis, name=name) 1518 1519 ~/software/anaconda3/envs/tf2/lib/python3.6/site-packages/tensorflow_core/python/ops/gen_array_ops.py in concat_v2(values, axis, name) 1116 pass # Add nodes to the TensorFlow graph. 1117 except _core._NotOkStatusException as e: -> 1118 _ops.raise_from_not_ok_status(e, name) 1119 # Add nodes to the TensorFlow graph. 1120 if not isinstance(values, (list, tuple)): ~/software/anaconda3/envs/tf2/lib/python3.6/site-packages/tensorflow_core/python/framework/ops.py in raise_from_not_ok_status(e, name) 6604 message = e.message + (" name: " + name if name is not None else "") 6605 # pylint: disable=protected-access -> 6606 six.raise_from(core._status_to_exception(e.code, message), None) 6607 # pylint: enable=protected-access 6608 ~/software/anaconda3/envs/tf2/lib/python3.6/site-packages/six.py in raise_from(value, from_value) InvalidArgumentError: OpKernel 'ConcatV2' has constraint on attr 'T' not in NodeDef '[N=0, Tidx=DT_INT32]', KernelDef: 'op: "ConcatV2" device_type: "GPU" constraint { name: "T" allowed_values { list { type: DT_INT32 } } } host_memory_arg: "values" host_memory_arg: "axis" host_memory_arg: "output"' [Op:ConcatV2] name: concat ------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------# 2. Map over class IDs nms_keep = [] print("shape {}".format(unique_pre_nms_class_ids.shape)) 打印出的结果:shape (0,) for i in range(unique_pre_nms_class_ids.shape[0]): nms_keep.append(nms_keep_map(unique_pre_nms_class_ids[i])) print("nms_kepp {}".format(nms_keep)) 打印出的结果:nms_kepp [] nms_keep = tf.concat(nms_keep, axis=0) ----------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------ 疑问是不是数据出问题了,如果是的话,怎么判断数据是有效的还是无效的
ainilian commented 4 years ago

解决了,换张图片初始化模型就行了

yunfei1999 commented 1 year ago

具体换图片的代码在哪里呢? img, img_meta, bboxes, labels = train_dataset[6] # [N, 4], shape:[N]=data:[62] # 这句吗? rgb_img = np.round(img + img_mean) ori_img = get_original_image(img, img_meta, img_mean)

yunfei1999 commented 1 year ago

@ainilian