渴望在Muliti级数据准备和可视化上进行射击对象检测
我遵循此
应该直接扩展此操作以处理多个类。
但是失败了。感谢您的帮助!
数据预定:
# By convention, our non-background classes start counting at 1. Given
# that we will be predicting just one class, we will therefore assign it a
# `class id` of 1.
duck_class_id = 1
num_classes = 1
category_index = {duck_class_id: {'id': duck_class_id, 'name': 'rubber_ducky'}}
# Convert class labels to one-hot; convert everything to tensors.
# The `label_id_offset` here shifts all classes by a certain number of indices;
# we do this here so that the model receives one-hot labels where non-background
# classes start counting at the zeroth index. This is ordinarily just handled
# automatically in our training binaries, but we need to reproduce it here.
label_id_offset = 1
train_image_tensors = []
gt_classes_one_hot_tensors = []
gt_box_tensors = []
for (train_image_np, gt_box_np) in zip(
train_images_np, gt_boxes):
train_image_tensors.append(tf.expand_dims(tf.convert_to_tensor(
train_image_np, dtype=tf.float32), axis=0))
gt_box_tensors.append(tf.convert_to_tensor(gt_box_np, dtype=tf.float32))
zero_indexed_groundtruth_classes = tf.convert_to_tensor(
np.ones(shape=[gt_box_np.shape[0]], dtype=np.int32) - label_id_offset)
gt_classes_one_hot_tensors.append(tf.one_hot(
zero_indexed_groundtruth_classes, num_classes))
print('Done prepping data.')
我认为问题是 Zero_indexed_groundTruth_classes ,如果有三个类,并且映射如何更改此行
zero_indexed_groundtruth_classes = tf.convert_to_tensor(
np.ones(shape=[gt_box_np.shape[0]], dtype=np.int32) - label_id_offset)
数据可视化:
如何更改可视化代码相应?
dummy_scores = np.array([1.0], dtype=np.float32) # give boxes a score of 100%
plt.figure(figsize=(30, 15))
for idx in range(5):
plt.subplot(2, 3, idx+1)
plot_detections(
train_images_np[idx],
gt_boxes[idx],
np.ones(shape=[gt_boxes[idx].shape[0]], dtype=np.int32),
dummy_scores, category_index)
plt.show()
非常
category_index = {
1: {'id': 1, 'name': 'a'},
2: {'id': 2, 'name': 'b'},
3: {'id': 2, 'name': 'c'}
}
num_classes = 3
and three pictures that No.1 has five boxes as a,b,b,c,c;
No.2 has two boxes as a,a;
No.3 has four boxes as a,b,c,a.
感谢!
I followed this instruction which is helpful on object detection and took hours to try to make muli-class tuning. It said
it should be straightforward to extend this to handle multiple classes.
But failed. Thanks for any help!
Data Prepratation:
# By convention, our non-background classes start counting at 1. Given
# that we will be predicting just one class, we will therefore assign it a
# `class id` of 1.
duck_class_id = 1
num_classes = 1
category_index = {duck_class_id: {'id': duck_class_id, 'name': 'rubber_ducky'}}
# Convert class labels to one-hot; convert everything to tensors.
# The `label_id_offset` here shifts all classes by a certain number of indices;
# we do this here so that the model receives one-hot labels where non-background
# classes start counting at the zeroth index. This is ordinarily just handled
# automatically in our training binaries, but we need to reproduce it here.
label_id_offset = 1
train_image_tensors = []
gt_classes_one_hot_tensors = []
gt_box_tensors = []
for (train_image_np, gt_box_np) in zip(
train_images_np, gt_boxes):
train_image_tensors.append(tf.expand_dims(tf.convert_to_tensor(
train_image_np, dtype=tf.float32), axis=0))
gt_box_tensors.append(tf.convert_to_tensor(gt_box_np, dtype=tf.float32))
zero_indexed_groundtruth_classes = tf.convert_to_tensor(
np.ones(shape=[gt_box_np.shape[0]], dtype=np.int32) - label_id_offset)
gt_classes_one_hot_tensors.append(tf.one_hot(
zero_indexed_groundtruth_classes, num_classes))
print('Done prepping data.')
I think the problem is zero_indexed_groundtruth_classes and if there are three classes and a mapping how to change this line
zero_indexed_groundtruth_classes = tf.convert_to_tensor(
np.ones(shape=[gt_box_np.shape[0]], dtype=np.int32) - label_id_offset)
Data visualization:
How to change visualization code correspondingly?
dummy_scores = np.array([1.0], dtype=np.float32) # give boxes a score of 100%
plt.figure(figsize=(30, 15))
for idx in range(5):
plt.subplot(2, 3, idx+1)
plot_detections(
train_images_np[idx],
gt_boxes[idx],
np.ones(shape=[gt_boxes[idx].shape[0]], dtype=np.int32),
dummy_scores, category_index)
plt.show()
Asssuming
category_index = {
1: {'id': 1, 'name': 'a'},
2: {'id': 2, 'name': 'b'},
3: {'id': 2, 'name': 'c'}
}
num_classes = 3
and three pictures that No.1 has five boxes as a,b,b,c,c;
No.2 has two boxes as a,a;
No.3 has four boxes as a,b,c,a.
Thanks a lot!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于多个类,您只需创建一个带有类的数组,然后将数组传递到该代码的这一部分,
其中gt_classes = [1,1,1 ...,2,2,2,],根据类的数量。这将帮助您进行多类对象检测。
如果您有其他疑问,您可以联系
For multiple classes, you can just simply create an array with classes and pass that array to this part of the code
where gt_classes = [1,1,1..., 2,2,2,] depending upon the number of classes. This will help you do multiclass object detection.
You can reach out if you have any further doubts