Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to give the input image which is to be convolved here ? #16

Closed
debanjana-in-tech opened this issue Mar 26, 2015 · 3 comments
Closed
Labels

Comments

@debanjana-in-tech
Copy link

No description provided.

@davidstutz
Copy link

You have to convert your input image to vec_t, i.e. std::vector<float>. When your are running OpenCV, you can convert your image as follows (I follow the conversion as used in mnist_parser.h):

float denominator = 255;
float min = -1;
float max = 1;
int padding = 2;
vec_t sample(3*H + 2*padding)*(W + 2*padding), min);
for (int i = 0; i < H; i++) { // Go over all rows
    for (int j = 0; j < W; j++) { // Go over all columns
        for (int c = 0; c < 3; c++) { // Go through all channels
            sample[W*H*c + W*(i + padding) + (j + padding)] = image.at<cv::Vec3b>(i, j)[c]/denominator*(max - min) + min;
        }
    }
}

As you can see, padding is applied (I am using a kernel of size 5 x 5 in the first convolutional layer). If your kernel is of size 2_k + 1 x 2_k + 1, then you should padd the image by k on each side. Further, the image is transformed to lie in [-1,1].

@edgarriba
Copy link
Member

@WithBestWishes Does this solve your problem?
Besides, check the provided example: #187

@xuanzhaopeng
Copy link

@davidstutz Could you kindly explain why should add padding k when I use 2k+1, 2k+1 kernel in first layer? I read the example cifar10, during the training, it use padding 0.
https://github.com/tiny-dnn/tiny-dnn/blob/master/examples/cifar10/train.cpp#L69

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants