【发布时间】:2018-04-25 19:56:20
【问题描述】:
我正在运行 github 存储库 tensorflow/object_deteciton 中的典型代码: https://github.com/tensorflow/models/tree/master/research/object_detection
特别是“object_detection_tutorial.ipynb”文件。主循环是这里的这一部分:
with detection_graph.as_default():
with tf.Session(graph=detection_graph) as sess:
# Definite input and output Tensors for detection_graph
image_tensor = detection_graph.get_tensor_by_name('image_tensor:0')
# Each box represents a part of the image where a particular object was detected.
detection_boxes = detection_graph.get_tensor_by_name('detection_boxes:0')
# Each score represent how level of confidence for each of the objects.
# Score is shown on the result image, together with the class label.
detection_scores = detection_graph.get_tensor_by_name('detection_scores:0')
detection_classes = detection_graph.get_tensor_by_name('detection_classes:0')
num_detections = detection_graph.get_tensor_by_name('num_detections:0')
for image_path in TEST_IMAGE_PATHS:
image = Image.open(image_path)
# the array based representation of the image will be used later in order to prepare the
# result image with boxes and labels on it.
image_np = load_image_into_numpy_array(image)
# Expand dimensions since the model expects images to have shape: [1, None, None, 3]
image_np_expanded = np.expand_dims(image_np, axis=0)
# Actual detection.
(boxes, scores, classes, num) = sess.run(
[detection_boxes, detection_scores, detection_classes, num_detections],
feed_dict={image_tensor: image_np_expanded})
# Visualization of the results of a detection.
vis_util.visualize_boxes_and_labels_on_image_array(
image_np,
np.squeeze(boxes),
np.squeeze(classes).astype(np.int32),
np.squeeze(scores),
category_index,
use_normalized_coordinates=True,
line_thickness=8)
plt.figure(figsize=IMAGE_SIZE)
plt.imshow(image_np)
我只是在寻找一些关于将图像识别的内容实际保存到数据框中的最佳方法的建议,该数据框将理想地存储为图像中检测到的每个对象检测到的对象的类别。
任何帮助将不胜感激(:
【问题讨论】:
-
我只能说,你那里的 cmets 太多了。好的 cmets 是稀疏的,因为好的代码是自我记录的。任何时候你想表达为什么你选择了一个不明显的特定算法或技术,你应该留下评论讨论为什么代码是这样编写的。任何时候你有一段代码,尽管标识符很好,但没有明确表达的目的,你可以留下评论记录代码的作用。不要留下包含可以通过阅读代码了解到的信息的 cmets。变量名、可理解的操作等
-
我不确定你是否知道,但这段代码取自 Github 上的教程,这就是我想它包含 cmets 的原因......
-
对此有何反馈?
-
我猜代码在新的 TF 版本中随着时间的推移发生了变化,但是你展示的这部分不在你描述的文件中。
-
@user27074 那么答案还有帮助吗?
标签: python tensorflow object-detection