【问题标题】:create_coco_tf_record.py from object detection API not creating tfrecord file来自对象检测 API 的 create_coco_tf_record.py 未创建 tfrecord 文件
【发布时间】:2021-02-10 15:02:53
【问题描述】:

我正在尝试以 coco 格式 (.json) 创建 tfrecord (.record) 文件。因此,我使用对象检测 api github 存储库中的 create_coco_tf_record.py 脚本的 this 稍作修改的版本。
我在 colab 上运行我的笔记本。以下是几行代码:

#Mount Google Drive.
from google.colab import drive
drive.mount('/content/gdrive') <br>

!pip install -U --pre tensorflow=="2.2.0"

#Download TensorFlow Model Garden.
import os
import pathlib
#cd into the TensorFlow directory in your Google Drive
%cd '/content/gdrive/My Drive/TensorFlow'
# Clone the tensorflow models repository if it doesn't already exist
if "models" in pathlib.Path.cwd().parts:
  while "models" in pathlib.Path.cwd().parts:
    os.chdir('..')
elif not pathlib.Path('models').exists():
  !git clone --depth 1 https://github.com/tensorflow/models

# Install the Object Detection API
%%bash
cd '/content/gdrive/My Drive/TensorFlow/models/research/'
protoc object_detection/protos/*.proto --python_out=.
cp object_detection/packages/tf2/setup.py .
python -m pip install .

#run model builder test
!python '/content/gdrive/My Drive/TensorFlow/models/research/object_detection/builders/model_builder_tf2_test.py'

!wget https://raw.githubusercontent.com/TannerGilbert/Tensorflow-Object-Detection-API-train-custom-Mask-R-CNN-model/master/create_coco_tf_record.py

# create tf record
!python create_coco_tf_record.py \
  --logtostderr \
  --train_image_dir='/content/gdrive/My Drive/TensorFlow/workspace/training_demo/images/combined/' \
  --test_image_dir='/content/gdrive/My Drive/TensorFlow/workspace/training_demo/images/combined/' \
  --train_annotations_file='/content/gdrive/My Drive/TensorFlow/workspace/training_demo/images/train_coco.json' \
  --test_annotations_file='/content/gdrive/My Drive/TensorFlow/workspace/training_demo/images/test_coco.json' \
  --output='/content/gdrive/My Drive/TensorFlow/workspace/training_demo/annotations/'

create_coco_tf_record.py 脚​​本运行没有任何错误。它是这样显示的:

2020-10-28 08:58:44.931401: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcudart.so.10.1
INFO:tensorflow:Found groundtruth annotations. Building annotations index.
I1028 08:58:46.678869 139783613331328 create_coco_tf_record.py:214] Found groundtruth annotations. Building annotations index.
INFO:tensorflow:0 images are missing annotations.
I1028 08:58:46.679595 139783613331328 create_coco_tf_record.py:227] 0 images are missing annotations.
INFO:tensorflow:On image 0 of 451
I1028 08:58:46.680609 139783613331328 create_coco_tf_record.py:232] On image 0 of 451
INFO:tensorflow:On image 100 of 451
I1028 08:58:51.800869 139783613331328 create_coco_tf_record.py:232] On image 100 of 451
INFO:tensorflow:On image 200 of 451
I1028 08:59:01.762672 139783613331328 create_coco_tf_record.py:232] On image 200 of 451
INFO:tensorflow:On image 300 of 451
I1028 08:59:22.197772 139783613331328 create_coco_tf_record.py:232] On image 300 of 451
INFO:tensorflow:On image 400 of 451
I1028 09:00:17.036898 139783613331328 create_coco_tf_record.py:232] On image 400 of 451
INFO:tensorflow:Finished writing, skipped 0 annotations.
I1028 09:00:32.919734 139783613331328 create_coco_tf_record.py:239] Finished writing, skipped 0 annotations.
INFO:tensorflow:Found groundtruth annotations. Building annotations index.
I1028 09:00:32.932144 139783613331328 create_coco_tf_record.py:214] Found groundtruth annotations. Building annotations index.
INFO:tensorflow:0 images are missing annotations.
I1028 09:00:32.932511 139783613331328 create_coco_tf_record.py:227] 0 images are missing annotations.
INFO:tensorflow:On image 0 of 152
I1028 09:00:32.932658 139783613331328 create_coco_tf_record.py:232] On image 0 of 152
INFO:tensorflow:On image 100 of 152
I1028 09:00:46.510094 139783613331328 create_coco_tf_record.py:232] On image 100 of 152
INFO:tensorflow:Finished writing, skipped 0 annotations.
I1028 09:01:08.650619 139783613331328 create_coco_tf_record.py:239] Finished writing, skipped 0 annotations.

它确实创建任何.record文件。

有谁知道这可能是什么问题?

提前致谢!

【问题讨论】:

  • 请分享一个能够重现您观察到的问题的独立笔记本。
  • 嘿@BobSmith,非常感谢您的回答。这是我问题的解决方案!这是我的colab 笔记本。但我仍然想知道为什么一个独立的笔记本可以完成这项工作而安装的却没有。你知道为什么吗?谢谢

标签: tensorflow google-colaboratory object-detection-api tfrecord coco


【解决方案1】:

您可以运行此命令在 Windows 机器上的 VS 代码终端中生成您的 .record 文件。 “Imp. - 不要使用'逗号'来包含您的路径,因为我已经提到只是复制/粘贴路径,就像我在评论中建议的那样”-

python create_coco_tf_record.py 
  --train_image_dir 'Path where you have your training dataset' 
  --test_image_dir 'Path where you have your validation dataset' 
  --train_annotations_file 'Path to your training dataset .json file' 
  --test__annotations_file 'Path to your validation dataset .json file' 
  --logtostderr --output_dir 'Path where do you want to generate your .record file'

还要记住并运行具有运行此代码所需的特定环境要求的代码。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-12
    • 2017-12-31
    • 1970-01-01
    • 1970-01-01
    • 2018-10-03
    • 2020-02-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多