how can I build my database for learning a network in keras?

I have some images that have been attacked with different kind of attacks like JPEG، salt & pepper,... now, I want to design a network that is fed with these images and their label and said what kind of attacks is done. but I do not know how can I make my database and prepare my training data? could you please help me with this issue? thanks in advance.

2 answers

  • answered 2018-10-12 07:52 Mete Han Kahraman

    There are multiple ways of handling datasets, in keras you can feed the network with a numpy array or a generator.

    Detailed documentation on generators :

    If you are going to use generators, before you do anything, separate your images by their labels into different directories. File hierarchy should look like

    • TrainingData
      • Label1
        • image1.jpg
        • image2.jpg
      • Label2
        • image1.jpg
        • image2.jpg

    If you are going to store all your data into a numpy array, I suggest putting all your data into a csv file and their labels should be the first or last column. I don't recommend this for big datasets since you may have not enough memory for all of your data.

    If you need code examples, googling "keras datagenerator example" will yield you a lot of them.

  • answered 2018-10-12 08:21 Novak

    I would recommend using generators because they are easy to write and are safe for running your code. As for organizing the data, the answer from @Mete is ok, but consider also making a csv with image names in one column and type of attack in other. Then you just go through the csv file row by row, doing whatever you need to do with it then.