我是 caffe 的新手,因此试图使用 MNIST 数据集构建模型,我执行了以下说明:
./data/mnist/get_mnist.sh
./examples/mnist/create_mnist.sh
./examples/mnist/train_lenet.sh
在最后一条指令的末尾,控制台上打印了一系列输出,最后几行是:
I0315 08:46:40.755457 2430 sgd_solver.cpp:106] Iteration 9900, lr = 0.00596843
I0315 08:46:48.754673 2430 solver.cpp:454] Snapshotting to binary proto file examples/mnist/lenet_iter_10000.caffemodel
I0315 08:46:48.761627 2430 sgd_solver.cpp:273] Snapshotting solver state to binary proto file examples/mnist/lenet_iter_10000.solverstate
I0315 08:46:48.832245 2430 solver.cpp:317] Iteration 10000, loss = 0.00262804
I0315 08:46:48.835681 2430 solver.cpp:337] Iteration 10000, Testing net (#0)
I0315 08:46:54.016222 2430 solver.cpp:404] Test net output #0: accuracy = 0.991
I0315 08:46:54.016377 2430 solver.cpp:404] Test net output #1: loss = 0.0300069 (* 1 = 0.0300069 loss)
I0315 08:46:54.016427 2430 solver.cpp:322] Optimization Done.
I0315 08:46:54.016474 2430 caffe.cpp:222] Optimization Done.
我现在尝试使用在examples/mnist/lenet_iter_10000.caffemodel中创建为binay proto文件的模型
我运行了以下命令,将我的图像作为测试模型的输入:
python python/classify.py --print_results --model_def examples/mnist/lenet.prototxt --pretrained_model examples/mnist/lenet_iter_10000.caffemodel --force_grayscale --center_only --labels_file data/mnist/mnist_words.txt --images_dim 28,28 /home/kishan/Desktop/gray1.jpg foo
我的图像是灰度 256*256 图像(我什至尝试过使用 256*256 RGB 图像)
但是发生错误说:
Traceback (most recent call last):
File "python/classify.py", line 154, in <module>
main(sys.argv)
File "python/classify.py", line 126, in main
channel_swap=channel_swap)
File "/home/kishan/deep-learning/caffe/python/caffe/classifier.py", line 40, in __init__
self.transformer.set_channel_swap(in_, channel_swap)
File "/home/kishan/deep-learning/caffe/python/caffe/io.py", line 216, in set_channel_swap
raise Exception('Channel swap needs to have the same number of '
Exception: Channel swap needs to have the same number of dimensions as the input channels.
我没有更改任何文件,除了我添加了这些代码行的分类.py:
parser.add_argument(
"--labels_file",
default=os.path.join(pycaffe_dir,
"../data/ilsvrc12/synset_words.txt"),
help="Readable label definition file."
)
parser.add_argument(
"--print_results",
action='store_true',
help="Write output text to stdout rather than serializing to a file."
)
parser.add_argument(
"--force_grayscale",
action='store_true',
help="Converts RGB images down to single-channel grayscale versions useful for single-channel networks like MNIST."
)
我的 ./examples/mnist 文件结构:
mnist/
|-- convert_mnist_data.cpp
|-- create_mnist.sh
|-- lenet_adadelta_solver.prototxt
|-- lenet_auto_solver.prototxt
|-- lenet_consolidated_solver.prototxt
|-- lenet_iter_10000.caffemodel
|-- lenet_iter_10000.solverstate
|-- lenet_iter_5000.caffemodel
|-- lenet_iter_5000.solverstate
|-- lenet_multistep_solver.prototxt
|-- lenet.prototxt
|-- lenet_solver_adam.prototxt
|-- lenet_solver.prototxt
|-- lenet_solver_rmsprop.prototxt
|-- lenet_train_test.prototxt
|-- mnist_autoencoder.prototxt
|-- mnist_autoencoder_solver_adadelta.prototxt
|-- mnist_autoencoder_solver_adagrad.prototxt
|-- mnist_autoencoder_solver_nesterov.prototxt
|-- mnist_autoencoder_solver.prototxt
|-- mnist_test_lmdb
| |-- data.mdb
| `-- lock.mdb
|-- mnist_train_lmdb
| |-- data.mdb
| `-- lock.mdb
|-- readme.md
|-- train_lenet_adam.sh
|-- train_lenet_consolidated.sh
|-- train_lenet_docker.sh
|-- train_lenet_rmsprop.sh
|-- train_lenet.sh
|-- train_mnist_autoencoder_adadelta.sh
|-- train_mnist_autoencoder_adagrad.sh
|-- train_mnist_autoencoder_nesterov.sh
`-- train_mnist_autoencoder.sh
./data/mnist 的文件结构:
mnist/
|-- get_mnist.sh
|-- t10k-images-idx3-ubyte
|-- t10k-labels-idx1-ubyte
|-- train-images-idx3-ubyte
`-- train-labels-idx1-ubyte
任何帮助,将不胜感激。