问题
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