最近需要使用yolo 9000的预训练模型,我用的是python接口,我这里分享一下我使用预训练模型的经验。我用的模型的官网地址为https://github.com/philipperemy/yolo-9000
我用的是其自带的detector.py,在yolo-9000/darknet/examples目录中,需要把它放在yolo-9000/darknet目录下,我修改的detector.py的代码为:
# Stupid python path shit.
# Instead just add darknet.py to somewhere in your python path
# OK actually that might not be a great idea, idk, work in progress
# Use at your own risk. or don't, i don't care
import sys, os
sys.path.append(os.path.join(os.getcwd(),'python/'))
import darknet as dn
net = dn.load_net("cfg/yolo9000.cfg", "../yolo9000-weights/yolo9000.weights", 0)
meta = dn.load_meta("cfg/combine9k.data")
# r = dn.detect(net, meta, "data/dog.jpg")
# print r
# print(r[0][0])
image_files = os.listdir(image_path)
with open("image_objects.txt","w") as file:
num=0
for image_file in image_files:
file_path=os.path.join(image_base_path,image_file)
predict = dn.detect(net, meta,file_path)
file.write(image_file)
for predict_object in predict:
# print r
# print(r[0][0])
image_files = os.listdir(image_path)
with open("image_objects.txt","w") as file:
num=0
for image_file in image_files:
file_path=os.path.join(image_base_path,image_file)
predict = dn.detect(net, meta,file_path)
file.write(image_file)
for predict_object in predict:
file.write(" "+predict_object[0])
file.write("\n")
num+=1
if(num%100==0):
print(num)
但是在运行detector.py的时候出现了如下的错误:
OSError: libdarknet.so: cannot open shared object file: No such file or directory
我使用的是gpu版本,最后发现只要在命令行输入:
export PATH=/usr/local/cuda-8.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64:$LD_LIBRARY_PATH
就行了。如果要使用gpu版本进行预测,参照官网的教程就行了
参考文献
[1].Yolo 9000.https://github.com/philipperemy/yolo-9000