How to build an image dataset for CNN?












0












$begingroup$


I don't understand how images are actually fed into a CNN? If I have a directory containing a few thousand images, what steps do I need to take in order to feed them to a neural network (for instance resizing, grey scale, labeling, etc) I don't understand how even the labeling of an image works. What would this dataset actually look like? Or can you not look at it at all (in a summarized form, I'm thinking something like a table)?










share|improve this question









$endgroup$

















    0












    $begingroup$


    I don't understand how images are actually fed into a CNN? If I have a directory containing a few thousand images, what steps do I need to take in order to feed them to a neural network (for instance resizing, grey scale, labeling, etc) I don't understand how even the labeling of an image works. What would this dataset actually look like? Or can you not look at it at all (in a summarized form, I'm thinking something like a table)?










    share|improve this question









    $endgroup$















      0












      0








      0





      $begingroup$


      I don't understand how images are actually fed into a CNN? If I have a directory containing a few thousand images, what steps do I need to take in order to feed them to a neural network (for instance resizing, grey scale, labeling, etc) I don't understand how even the labeling of an image works. What would this dataset actually look like? Or can you not look at it at all (in a summarized form, I'm thinking something like a table)?










      share|improve this question









      $endgroup$




      I don't understand how images are actually fed into a CNN? If I have a directory containing a few thousand images, what steps do I need to take in order to feed them to a neural network (for instance resizing, grey scale, labeling, etc) I don't understand how even the labeling of an image works. What would this dataset actually look like? Or can you not look at it at all (in a summarized form, I'm thinking something like a table)?







      machine-learning python neural-network keras cnn






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 25 mins ago









      55thSwiss55thSwiss

      85




      85






















          2 Answers
          2






          active

          oldest

          votes


















          0












          $begingroup$

          Dataset just consists of Features and Labels. Here features are your images and labels are the classes.



          There is a fit() method for every CNN model, which will take in Features and Labels, and performs training.



          for the first layer, you need to mention the input dimension of image, and the output layer should be a softmax (if you're doing classification) with dimension as the number of classes you have.



          model = Sequential()
          model.add(Conv2D(32, (3, 3), padding='same', input_shape=(64, 64, 3)))
          model.add(Activation('relu'))
          model.add(Conv2D(32, (3, 3)))
          model.add(Activation('relu'))
          model.add(MaxPooling2D(pool_size=(2, 2)))
          model.add(Dropout(0.25))

          model.add(Flatten())
          model.add(Dense(512))
          model.add(Activation('relu'))
          model.add(Dropout(0.5))
          model.add(Dense(num_classes))
          model.add(Activation('softmax'))

          model.compile(loss='categorical_crossentropy', optimizer='Adam', metrics=['accuracy'])

          model.fit(x_train, y_train, epochs=10)


          The above is the code for training a Keras sequenctioal model.



          General Points:




          1. input_shape should be the dimension of X_train.

          2. You need to get this shape when you do X_train.shape (numpy)

          3. Convolutions are then applied with respective Activations

          4. Dropout and Pooling layers are optional.

          5. After the convolution layers, the data is flattened. using Flatten()

          6. Then it is sent to few Fully Connected layers

          7. The last but one layer should have the dimensions of number of classes

          8. Last layer will be softmax.

          9. Now, compile the model with the loss, optimizer and metric

          10. Then fit()


          Vote up ;) if you like it.





          share









          $endgroup$





















            0












            $begingroup$

            This is a very packed question. Let's try to go through it and I will try to provide some example for image processing using a CNN.



            How to structure the data?



            The shape of the variable which you will use as the input for your CNN will depend on the package you choose. I prefer using tensorflow, which is developed by Google. If you are planning on using a pretty standard architecture, then there is a very useful wrapper library named Keras which will help make designing and training a CNN very easy.



            When using tensorflow you will want to get your set of images into a numpy matrix. The first dimension is your instances, then your image dimensions and finally the last dimension is for channels.



            So for example if you are using MNIST data as shown below, then you are working with greyscale images which each have dimensions 28 by 28. Then the numpy matrix shape that you would feed into your deep learning model would be (n, 28, 28, 1), where $n$ is the number of images you have in your dataset.



            enter image description here





            share









            $endgroup$














              Your Answer





              StackExchange.ifUsing("editor", function () {
              return StackExchange.using("mathjaxEditing", function () {
              StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
              StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
              });
              });
              }, "mathjax-editing");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "557"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f48390%2fhow-to-build-an-image-dataset-for-cnn%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0












              $begingroup$

              Dataset just consists of Features and Labels. Here features are your images and labels are the classes.



              There is a fit() method for every CNN model, which will take in Features and Labels, and performs training.



              for the first layer, you need to mention the input dimension of image, and the output layer should be a softmax (if you're doing classification) with dimension as the number of classes you have.



              model = Sequential()
              model.add(Conv2D(32, (3, 3), padding='same', input_shape=(64, 64, 3)))
              model.add(Activation('relu'))
              model.add(Conv2D(32, (3, 3)))
              model.add(Activation('relu'))
              model.add(MaxPooling2D(pool_size=(2, 2)))
              model.add(Dropout(0.25))

              model.add(Flatten())
              model.add(Dense(512))
              model.add(Activation('relu'))
              model.add(Dropout(0.5))
              model.add(Dense(num_classes))
              model.add(Activation('softmax'))

              model.compile(loss='categorical_crossentropy', optimizer='Adam', metrics=['accuracy'])

              model.fit(x_train, y_train, epochs=10)


              The above is the code for training a Keras sequenctioal model.



              General Points:




              1. input_shape should be the dimension of X_train.

              2. You need to get this shape when you do X_train.shape (numpy)

              3. Convolutions are then applied with respective Activations

              4. Dropout and Pooling layers are optional.

              5. After the convolution layers, the data is flattened. using Flatten()

              6. Then it is sent to few Fully Connected layers

              7. The last but one layer should have the dimensions of number of classes

              8. Last layer will be softmax.

              9. Now, compile the model with the loss, optimizer and metric

              10. Then fit()


              Vote up ;) if you like it.





              share









              $endgroup$


















                0












                $begingroup$

                Dataset just consists of Features and Labels. Here features are your images and labels are the classes.



                There is a fit() method for every CNN model, which will take in Features and Labels, and performs training.



                for the first layer, you need to mention the input dimension of image, and the output layer should be a softmax (if you're doing classification) with dimension as the number of classes you have.



                model = Sequential()
                model.add(Conv2D(32, (3, 3), padding='same', input_shape=(64, 64, 3)))
                model.add(Activation('relu'))
                model.add(Conv2D(32, (3, 3)))
                model.add(Activation('relu'))
                model.add(MaxPooling2D(pool_size=(2, 2)))
                model.add(Dropout(0.25))

                model.add(Flatten())
                model.add(Dense(512))
                model.add(Activation('relu'))
                model.add(Dropout(0.5))
                model.add(Dense(num_classes))
                model.add(Activation('softmax'))

                model.compile(loss='categorical_crossentropy', optimizer='Adam', metrics=['accuracy'])

                model.fit(x_train, y_train, epochs=10)


                The above is the code for training a Keras sequenctioal model.



                General Points:




                1. input_shape should be the dimension of X_train.

                2. You need to get this shape when you do X_train.shape (numpy)

                3. Convolutions are then applied with respective Activations

                4. Dropout and Pooling layers are optional.

                5. After the convolution layers, the data is flattened. using Flatten()

                6. Then it is sent to few Fully Connected layers

                7. The last but one layer should have the dimensions of number of classes

                8. Last layer will be softmax.

                9. Now, compile the model with the loss, optimizer and metric

                10. Then fit()


                Vote up ;) if you like it.





                share









                $endgroup$
















                  0












                  0








                  0





                  $begingroup$

                  Dataset just consists of Features and Labels. Here features are your images and labels are the classes.



                  There is a fit() method for every CNN model, which will take in Features and Labels, and performs training.



                  for the first layer, you need to mention the input dimension of image, and the output layer should be a softmax (if you're doing classification) with dimension as the number of classes you have.



                  model = Sequential()
                  model.add(Conv2D(32, (3, 3), padding='same', input_shape=(64, 64, 3)))
                  model.add(Activation('relu'))
                  model.add(Conv2D(32, (3, 3)))
                  model.add(Activation('relu'))
                  model.add(MaxPooling2D(pool_size=(2, 2)))
                  model.add(Dropout(0.25))

                  model.add(Flatten())
                  model.add(Dense(512))
                  model.add(Activation('relu'))
                  model.add(Dropout(0.5))
                  model.add(Dense(num_classes))
                  model.add(Activation('softmax'))

                  model.compile(loss='categorical_crossentropy', optimizer='Adam', metrics=['accuracy'])

                  model.fit(x_train, y_train, epochs=10)


                  The above is the code for training a Keras sequenctioal model.



                  General Points:




                  1. input_shape should be the dimension of X_train.

                  2. You need to get this shape when you do X_train.shape (numpy)

                  3. Convolutions are then applied with respective Activations

                  4. Dropout and Pooling layers are optional.

                  5. After the convolution layers, the data is flattened. using Flatten()

                  6. Then it is sent to few Fully Connected layers

                  7. The last but one layer should have the dimensions of number of classes

                  8. Last layer will be softmax.

                  9. Now, compile the model with the loss, optimizer and metric

                  10. Then fit()


                  Vote up ;) if you like it.





                  share









                  $endgroup$



                  Dataset just consists of Features and Labels. Here features are your images and labels are the classes.



                  There is a fit() method for every CNN model, which will take in Features and Labels, and performs training.



                  for the first layer, you need to mention the input dimension of image, and the output layer should be a softmax (if you're doing classification) with dimension as the number of classes you have.



                  model = Sequential()
                  model.add(Conv2D(32, (3, 3), padding='same', input_shape=(64, 64, 3)))
                  model.add(Activation('relu'))
                  model.add(Conv2D(32, (3, 3)))
                  model.add(Activation('relu'))
                  model.add(MaxPooling2D(pool_size=(2, 2)))
                  model.add(Dropout(0.25))

                  model.add(Flatten())
                  model.add(Dense(512))
                  model.add(Activation('relu'))
                  model.add(Dropout(0.5))
                  model.add(Dense(num_classes))
                  model.add(Activation('softmax'))

                  model.compile(loss='categorical_crossentropy', optimizer='Adam', metrics=['accuracy'])

                  model.fit(x_train, y_train, epochs=10)


                  The above is the code for training a Keras sequenctioal model.



                  General Points:




                  1. input_shape should be the dimension of X_train.

                  2. You need to get this shape when you do X_train.shape (numpy)

                  3. Convolutions are then applied with respective Activations

                  4. Dropout and Pooling layers are optional.

                  5. After the convolution layers, the data is flattened. using Flatten()

                  6. Then it is sent to few Fully Connected layers

                  7. The last but one layer should have the dimensions of number of classes

                  8. Last layer will be softmax.

                  9. Now, compile the model with the loss, optimizer and metric

                  10. Then fit()


                  Vote up ;) if you like it.






                  share











                  share


                  share










                  answered 7 mins ago









                  William ScottWilliam Scott

                  1063




                  1063























                      0












                      $begingroup$

                      This is a very packed question. Let's try to go through it and I will try to provide some example for image processing using a CNN.



                      How to structure the data?



                      The shape of the variable which you will use as the input for your CNN will depend on the package you choose. I prefer using tensorflow, which is developed by Google. If you are planning on using a pretty standard architecture, then there is a very useful wrapper library named Keras which will help make designing and training a CNN very easy.



                      When using tensorflow you will want to get your set of images into a numpy matrix. The first dimension is your instances, then your image dimensions and finally the last dimension is for channels.



                      So for example if you are using MNIST data as shown below, then you are working with greyscale images which each have dimensions 28 by 28. Then the numpy matrix shape that you would feed into your deep learning model would be (n, 28, 28, 1), where $n$ is the number of images you have in your dataset.



                      enter image description here





                      share









                      $endgroup$


















                        0












                        $begingroup$

                        This is a very packed question. Let's try to go through it and I will try to provide some example for image processing using a CNN.



                        How to structure the data?



                        The shape of the variable which you will use as the input for your CNN will depend on the package you choose. I prefer using tensorflow, which is developed by Google. If you are planning on using a pretty standard architecture, then there is a very useful wrapper library named Keras which will help make designing and training a CNN very easy.



                        When using tensorflow you will want to get your set of images into a numpy matrix. The first dimension is your instances, then your image dimensions and finally the last dimension is for channels.



                        So for example if you are using MNIST data as shown below, then you are working with greyscale images which each have dimensions 28 by 28. Then the numpy matrix shape that you would feed into your deep learning model would be (n, 28, 28, 1), where $n$ is the number of images you have in your dataset.



                        enter image description here





                        share









                        $endgroup$
















                          0












                          0








                          0





                          $begingroup$

                          This is a very packed question. Let's try to go through it and I will try to provide some example for image processing using a CNN.



                          How to structure the data?



                          The shape of the variable which you will use as the input for your CNN will depend on the package you choose. I prefer using tensorflow, which is developed by Google. If you are planning on using a pretty standard architecture, then there is a very useful wrapper library named Keras which will help make designing and training a CNN very easy.



                          When using tensorflow you will want to get your set of images into a numpy matrix. The first dimension is your instances, then your image dimensions and finally the last dimension is for channels.



                          So for example if you are using MNIST data as shown below, then you are working with greyscale images which each have dimensions 28 by 28. Then the numpy matrix shape that you would feed into your deep learning model would be (n, 28, 28, 1), where $n$ is the number of images you have in your dataset.



                          enter image description here





                          share









                          $endgroup$



                          This is a very packed question. Let's try to go through it and I will try to provide some example for image processing using a CNN.



                          How to structure the data?



                          The shape of the variable which you will use as the input for your CNN will depend on the package you choose. I prefer using tensorflow, which is developed by Google. If you are planning on using a pretty standard architecture, then there is a very useful wrapper library named Keras which will help make designing and training a CNN very easy.



                          When using tensorflow you will want to get your set of images into a numpy matrix. The first dimension is your instances, then your image dimensions and finally the last dimension is for channels.



                          So for example if you are using MNIST data as shown below, then you are working with greyscale images which each have dimensions 28 by 28. Then the numpy matrix shape that you would feed into your deep learning model would be (n, 28, 28, 1), where $n$ is the number of images you have in your dataset.



                          enter image description here






                          share











                          share


                          share










                          answered 6 mins ago









                          JahKnowsJahKnows

                          5,207727




                          5,207727






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Data Science Stack Exchange!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              Use MathJax to format equations. MathJax reference.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f48390%2fhow-to-build-an-image-dataset-for-cnn%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Callistus I

                              Tabula Rosettana

                              How to label and detect the document text images