Reputation: 576
I did this tutorial to train my model to detect hololens.
Now, I created a new Pascal Voc dataset of "guitar".
I want to take my actual model that detect hololens to detect hololens and guitar.
In step 3, I change these lines:
trainer.setDataDirectory(data_directory="hololens")
trainer.setTrainConfig(object_names_array=["hololens"], batch_size=4, num_experiments=100, train_from_pretrained_model="pretrained-yolov3.h5")
to:
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")
The "violao" folder struct is:
-violao
--train
---anottations
----<xml_files>
---images
----<images_files>
My annotation in these images is "violao".
When I run this code:
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()
I get this error:
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()
What am I doing wrong??
Upvotes: 1
Views: 1275
Reputation: 23
Try this:
trainer.setTrainConfig(object_names_array=[], batch_size=4, num_experiments=200, train_from_pretrained_model="---.h5")
object_names_array=[]
will select by default annotation from your xml.
Upvotes: 2
Reputation: 28
I think you misspelled anottations with a double t
My problem was that I entered the name of the folder here and not the object
object_names_array=["object name in the Label"]
Upvotes: 0
Reputation: 467
I think key error is this
Some labels have no annotations! Please revise the list of labels in
your configuration.
I managed to reproduce similar issue by adding new label in the object_names_array list that does not exist in training dataset annotations and I get these errors
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()
Solution
If it still doesn't work try training your model from given pretrainged yolov3 model https://github.com/OlafenwaMoses/ImageAI/releases/download/essential-v4/pretrained-yolov3.h5
Upvotes: 1