Channel swap needs to have the same number of dimensions as the input channels error .

105 views
Skip to first unread message

Kishan

unread,
Mar 14, 2016, 11:48:18 PM3/14/16
to Caffe Users
Hi all , 

I am new to caffe thus was trying to build a model using the MNIST dataset , I have executed the following instructions :

  • ./data/mnist/get_mnist.sh
  • ./examples/mnist/create_mnist.sh
  • ./examples/mnist/train_lenet.sh
At the end of the last instruction, a series of outputs were printed on the console , the last few lines of it is :

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.

I tried to now use the model created as binay proto file in examples/mnist/lenet_iter_10000.caffemodel

i ran the following command giving my image as input for testing the model:

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

My image is a gray scale 256*256 image (I have tried even with a 256*256 RGB image)

However an error occurs saying :

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.


I haven't changed any of the files , except classify.py where i have added these line of code :

    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."
    )


My file structure for the ./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


File structure for /data/mnist :

mnist/
|-- get_mnist.sh
|-- t10k-images-idx3-ubyte
|-- t10k-labels-idx1-ubyte
|-- train-images-idx3-ubyte
`-- train-labels-idx1-ubyte

Any help would be appreciated as i desperately need to get this right .

Reply all
Reply to author
Forward
0 new messages