Caffe, how to run classify.py for a set of images

拜拜、爱过 提交于 2019-12-23 01:13:42

问题


I installed Caffe on Linux successfully. Then I failed to make it work with Matlab. So I installed it with Python following the tutorial of Pete Warden. However, I never used Python before I just run the command "python python/classify.py --print_results examples/images/cat.jpg foo" and it works.

My question is how can I test calssify.py for a set images rather than a single image? I tried to read images from test directory as following

cd caffe
Python
Import os
For file in os.listdir(“example/images”):
     python/classify.py --print_results os.path.join(“examples/images/”,file) foo

but it returns each time

Error; Syntax inccorct

I just work intuitively as in Matlab. Do I need to compile classify.py before using it? Is the passage of arguments correct?

Thank you in advance.


回答1:


well, this works for files in a dir

mypath = './'
files = [ f for f in listdir(mypath) if isfile(join(mypath,f)) ]
for f in files:
    print join(mypath,f)

so perhaps you should modify yours to something like

import os
from os.path import isfile, join

mypath = './example/images/'
files = [ f for f in listdir(mypath) if isfile(join(mypath,f)) ]
for f in files:
    cmd = "python python/classify.py --print_results %s foo" % join(mypath,f)
    os.system(cmd)


来源:https://stackoverflow.com/questions/32171454/caffe-how-to-run-classify-py-for-a-set-of-images

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!