训练模型来检测新的物体

2024-10-03 21:29:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我做了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()

我做错什么了??你知道吗


Tags: infromselfsizemodelobjectbatchtrain