Giter Club home page Giter Club logo

image-classification-with-deep-convolutional-neural-networks's People

Contributors

bhiziroglu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

image-classification-with-deep-convolutional-neural-networks's Issues

A question about cifar10 dataset loading

Hi, thanks for sharing your code. It really helps me a lot.
I try to add following code in the function pair<Tensor, Tensor> Cifar::read_data , and expect to get one of the image files :

Tensor tmp=images[i].clone();
tmp=tmp.permute({1,2,0}).to(torch::kU8);  
cv::Mat image(32,32,CV_8UC3);
std::memcpy((void *)image.data,tmp.data_ptr(),sizeof(torch::kU8)*tmp.numel());
char imgpath[814];
sprintf(imgpath,"/my/path/%d.png",i+1);
cv::imwrite(imgpath,image); 

However, I always get an image file that looks non sense.
image exported
I don't know what's wrong, because transforming between Tensor and Mat is too complex for me. So I try to implement my own read_data function, and the problem is gone. It turns out the image above is from a frog.
Here is my code

pair<Tensor, Tensor> Cifar::read_data(const string &root, int train){
    int num_samples;
    vector<string> files;
    if(train==0){
        files = trainBatchFiles;
        num_samples = 50000;
    }else{
        files = testBatchFiles;
        num_samples = 10000;
    }
    auto images =torch::empty({num_samples, 3,32,32}, torch::kByte);
    auto targets = torch::empty(num_samples, torch::kByte);
    int labelr(0);
    Mat image(32,32,CV_8UC3,cv::Scalar::all(0));
    char* pData=(char*)image.data;
    int tot_img=0;
    for (const auto &file : files)
    {
        const auto path = join_paths(root, file);
        FILE * fptr=fopen(path.c_str(),"rb");
        if(fptr== nullptr){
            cout<<"Open error!"<<endl;
            fclose(fptr);
            continue;
        }
        for(int id_img=0; id_img<1e4;id_img++,tot_img++){
            fread(&labelr,sizeof(char),1,fptr);
            //cout<<labelr<<endl;
            for(int id_pic=0;id_pic<32*32;id_pic++){
                fread(pData+id_pic*3+2,sizeof(char),1,fptr);
            }
            for(int id_pic=0;id_pic<32*32;id_pic++){
                fread(pData+id_pic*3+1,sizeof(char),1,fptr);
            }
            for(int id_pic=0;id_pic<32*32;id_pic++){
                fread(pData+id_pic*3,sizeof(char),1,fptr);
            }
            images[tot_img]=torch::from_blob(image.data,{3,32,32},torch::kByte);
            targets[tot_img]=labelr;
        }
    }
   
    return {images.to(torch::kFloat32).div_(255), targets.to(torch::kInt64)};
}

As far as I am concerned, I will appreciate it if you could check these code, and leave me some hint about what causes the noise in the image exported.
Thank you!

How to use dnn

Thank you for sharing the project! It is a good practice to walk-through the process. I followed your instruction and finished the training.My understanding is the AlexNet intends to do the object detection and classification. One question is How to use your program to do inference for a given image?
The main() does not take any argument, so I do not know what to do next. It would be great if you can shed some light on it.

This is not an issue, rather it is a question for advice.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.