我知道微调caffe模型的命令是这样的:
caffe train -solver examples/finetuning_on_flickr_style/solver.prototxt -weights models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel
由于某些环境原因(caffe安装在root中,python env安装在用户中,当我使用caffe命令时将始终使用root python env),我无法像这样成功运行caffe,会得到如下错误:
File "/home/projec/test.py", line 8, in <module>
import caffe
File "/opt/caffe_gpu/python/caffe/__init__.py", line 1, in <module>
from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver, NCCL, Timer
File "/opt/caffe_gpu/python/caffe/pycaffe.py", line 11, in <module>
import numpy as np
File "/home/anaconda3/envs/python27/lib/python2.7/site-packages/numpy/__init__.py", line 142, in <module>
from . import add_newdocs
File "/home/anaconda3/envs/python27/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/home/anaconda3/envs/python27/lib/python2.7/site-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/home/anaconda3/envs/python27/lib/python2.7/site-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/home/anaconda3/envs/python27/lib/python2.7/site-packages/numpy/core/__init__.py", line 74, in <module>
from numpy.testing.nosetester import _numpy_tester
File "/home/anaconda3/envs/python27/lib/python2.7/site-packages/numpy/testing/__init__.py", line 10, in <module>
from unittest import TestCase
File "/home/anaconda3/envs/python27/lib/python2.7/unittest/__init__.py", line 64, in <module>
from .main import TestProgram, main
File "/home/anaconda3/envs/python27/lib/python2.7/unittest/main.py", line 7, in <module>
from . import loader, runner
File "/home/anaconda3/envs/python27/lib/python2.7/unittest/runner.py", line 7, in <module>
from .signals import registerResult
File "/home/anaconda3/envs/python27/lib/python2.7/unittest/signals.py", line 2, in <module>
import weakref
File "/home/anaconda3/envs/python27/lib/python2.7/weakref.py", line 13, in <module>
from _weakref import _remove_dead_weakref
实际上,当我输入“from _weakref import _remove_dead_weakref”时,python2.7中没有错误:
Python 2.7.14 |Anaconda, Inc.| (default, Nov 20 2017, 18:04:19)
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from _weakref import _remove_dead_weakref
>>>
所以,我在* .py文件中使用caffe可以训练成功,但是我不知道微调命令中“-weight”的python API是什么?* .py文件是这样的:
import caffe
import numpy as np
caffe.set_mode_gpu()
caffe.set_device(0)
solver= caffe.get_solver("/home/project/test.prototxt")
solver.solve()
有人能告诉我如何在* .py文件中设置“weight”参数吗?
答案 0 :(得分:2)
import caffe
import numpy as np
caffe.set_mode_gpu()
caffe.set_device(0)
solver= caffe.get_solver("/home/project/test.prototxt")
weights = "/home/project/test.caffemodel"
solver.net.copy_from(weights);
for net in solver.test_nets:
net.copy_from(weights)
solver.solve()