【问题标题】:Train model to detect new objects - YoloV3训练模型以检测新对象 - YoloV3
【发布时间】:2019-11-17 20:23:37
【问题描述】:

我使用this tutorial 训练我的模型来检测全息透镜。

现在,我创建了一个新的“吉他”Pascal Voc 数据集。

我想用检测全息透镜的实际模型来检测全息透镜和吉他。

在第 3 步中,我更改了以下几行:

trainer.setDataDirectory(data_directory="hololens")
trainer.setTrainConfig(object_names_array=["hololens"], batch_size=4, num_experiments=100, train_from_pretrained_model="pretrained-yolov3.h5")

到:

trainer.setDataDirectory(data_directory="violao")
trainer.setTrainConfig(object_names_array=["hololens", "violao"], batch_size=4, num_experiments=100, train_from_pretrained_model="drive/My Drive/PhoHast/my_model.h5")

“violao”文件夹结构是:

-violao
--train
---anottations
----<xml_files>
---images
----<images_files>

我在这些图片中的注释是“violao”。

当我运行这段代码时:

from imageai.Detection.Custom import DetectionModelTrainer
trainer = DetectionModelTrainer()
trainer.setModelTypeAsYOLOv3()
trainer.setDataDirectory(data_directory="violao")
trainer.setTrainConfig(object_names_array=["hololens", "violao"], batch_size=4, num_experiments=100, train_from_pretrained_model="my_model.h5")
trainer.trainModel()

我收到此错误:

Generating anchor boxes for training images and annotation...
[Errno 21] Is a directory: 'violao/train/annotations/.ipynb_checkpoints'
Ignore this bad annotation: violao/train/annotations/.ipynb_checkpoints
Average IOU for 9 anchors: 0.96
Anchor Boxes generated.
Detection configuration saved in  violao/json/detection_config.json
Some labels have no annotations! Please revise the list of labels in your configuration.
Training on:    None
Training with Batch Size:  4
Number of Experiments:  100
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-11-2e7a3bd0b6ee> in <module>()
      5 trainer.setDataDirectory(data_directory="violao")
      6 trainer.setTrainConfig(object_names_array=["hololens", "violao"], batch_size=4, num_experiments=100, train_from_pretrained_model="drive/My Drive/PhoHast/PhoHastV1.h5")
----> 7 trainer.trainModel()

1 frames
/usr/local/lib/python3.6/dist-packages/imageai/Detection/Custom/__init__.py in trainModel(self)
    231             shuffle=True,
    232             jitter=0.3,
--> 233             norm=normalize
    234         )
    235 

/usr/local/lib/python3.6/dist-packages/imageai/Detection/Custom/generator.py in __init__(self, instances, anchors, labels, downsample, max_box_per_image, batch_size, min_net_size, max_net_size, shuffle, jitter, norm)
     34         self.net_w              = 416
     35 
---> 36         if shuffle: np.random.shuffle(self.instances)
     37 
     38     def __len__(self):

mtrand.pyx in numpy.random.mtrand.RandomState.shuffle()

TypeError: object of type 'NoneType' has no len()

我做错了什么??

【问题讨论】:

    标签: python python-3.x tensorflow object-detection yolo


    【解决方案1】:

    我认为关键错误是这个

    Some labels have no annotations! Please revise the list of labels in
    your configuration.
    

    我设法通过在 object_names_array 列表中添加训练数据集注释中不存在的新标签来重现类似问题,我得到了这些错误

    Some labels have no annotations! Please revise the list of labels in your configuration.
    ...
    Training on:    None
    ...
    TypeError: object of type 'NoneType' has no len()
    

    解决方案

    1. 确保所有 object_names_array 标签都在您的数据集中,在您的情况下为“hololens”和“violao”。我假设您仅使用带有“violao”标记图像的数据集,因此 ImageAI 抱怨它无法找到 hololens 训练数据,即使您也指定在“hololens”上进行训练(假设您正在训练新模型并且它不知道训练前的任何标签,例如,如果你只留下 ["violao"] 它不会检测到 hololens,因为它对此一无所知。)
    2. data_directory 路径中删除不是 trainvalidation 的文件夹。当您添加标签等时,似乎从其他会话(很可能是缓存文件夹)生成的训练文件可能会干扰训练。

    如果仍然不起作用,请尝试从给定的预训练 yolov3 模型 https://github.com/OlafenwaMoses/ImageAI/releases/download/essential-v4/pretrained-yolov3.h5 训练您的模型

    【讨论】:

      【解决方案2】:

      试试这个:

      trainer.setTrainConfig(object_names_array=[], batch_size=4, num_experiments=200, train_from_pretrained_model="---.h5")
      

      object_names_array=[] 将默认从您的 xml 中选择注释。

      【讨论】:

        【解决方案3】:

        我认为你用双 t 拼错了 annotations

        我的问题是我在这里输入了文件夹的名称而不是对象

        object_names_array=["object name in the Label"]
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-01-15
          • 2019-06-21
          • 2019-01-22
          • 2018-05-04
          • 1970-01-01
          • 2021-06-04
          相关资源
          最近更新 更多