1.先按《Win10下ImageAI-gpu(tensorflow-gpu)环境安装(cuda及cuDNN自动安装)及实时对象检测》安装好。
2.下载pretrained-yolov3.h5,放到temp.py同一目录下。
3.下载hololens数据集,放到temp.py同一目录下。
4.编写代码开始训练。
from imageai.Detection.Custom import DetectionModelTrainer
trainer = DetectionModelTrainer()
trainer.setModelTypeAsYOLOv3()
trainer.setDataDirectory(data_directory="hololens")
trainer.setTrainConfig(object_names_array=["hololens"], batch_size=2, num_experiments=100, train_from_pretrained_model="pretrained-yolov3.h5")
trainer.trainModel()
batch_size=2是关键,否则可能出现以下错误
Resource exhausted: OOM when allocating tensor with shape[8,1024,14,14] and type float on /job:localhost/replica:0/task:0/device:GPU:0 by allocator GPU_0_bfc