How to predict an image among 10 classes instead of two classes












-4














I am new to deep learning and I am trying to predict an image from 10 classes.



I found the code below but only considers two classes. How can I adjust the code to 10 classes?



import numpy as np
from keras.preprocessing import image
test_image = image.load_img(path = 'dataset/single_prediction/cat_or_dog_1.jpg',
target_size = (64, 64))
test_image = image.img_to_array(test_image)
test_image = np.expand_dims(test_image, axis = 0)

result = classifier.predict(test_image)
indices = training_set.class_indices
if result[0][0] == 1:
prediction = 'dog'
else:
prediction = 'cat'









share|improve this question





























    -4














    I am new to deep learning and I am trying to predict an image from 10 classes.



    I found the code below but only considers two classes. How can I adjust the code to 10 classes?



    import numpy as np
    from keras.preprocessing import image
    test_image = image.load_img(path = 'dataset/single_prediction/cat_or_dog_1.jpg',
    target_size = (64, 64))
    test_image = image.img_to_array(test_image)
    test_image = np.expand_dims(test_image, axis = 0)

    result = classifier.predict(test_image)
    indices = training_set.class_indices
    if result[0][0] == 1:
    prediction = 'dog'
    else:
    prediction = 'cat'









    share|improve this question



























      -4












      -4








      -4







      I am new to deep learning and I am trying to predict an image from 10 classes.



      I found the code below but only considers two classes. How can I adjust the code to 10 classes?



      import numpy as np
      from keras.preprocessing import image
      test_image = image.load_img(path = 'dataset/single_prediction/cat_or_dog_1.jpg',
      target_size = (64, 64))
      test_image = image.img_to_array(test_image)
      test_image = np.expand_dims(test_image, axis = 0)

      result = classifier.predict(test_image)
      indices = training_set.class_indices
      if result[0][0] == 1:
      prediction = 'dog'
      else:
      prediction = 'cat'









      share|improve this question















      I am new to deep learning and I am trying to predict an image from 10 classes.



      I found the code below but only considers two classes. How can I adjust the code to 10 classes?



      import numpy as np
      from keras.preprocessing import image
      test_image = image.load_img(path = 'dataset/single_prediction/cat_or_dog_1.jpg',
      target_size = (64, 64))
      test_image = image.img_to_array(test_image)
      test_image = np.expand_dims(test_image, axis = 0)

      result = classifier.predict(test_image)
      indices = training_set.class_indices
      if result[0][0] == 1:
      prediction = 'dog'
      else:
      prediction = 'cat'






      python keras classification predict






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 22 at 8:29









      Vivek Kumar

      15.2k41851




      15.2k41851










      asked Nov 20 at 14:24









      Omar Basubeit

      1




      1
























          1 Answer
          1






          active

          oldest

          votes


















          -3














          Omar, my suggestion is for you to study a little further the libs you're using, such as Keras (mainly) and Numpy.



          This kind of question is going to be downvoted from users, because goes against the best practices from Stack Overflow, since you're asking for someone to give you the full code as an answer without looking out by yourself and detailing the specific challenge you're facing with which class, and not detailing the whole aspect of your code as well (such as the classifier object, which is not detailed where it came from, and guessing is not a good method to help here).



          Now, jumping to your problem, I suggest:




          1. Understand better the model from keras and its implications, on how to load models: https://keras.io/models/about-keras-models/

          2. Take a closer look on keras documentation and its methods
            https://keras.io/preprocessing/image/

          3. Take a look on this answer: https://stackoverflow.com/a/43470074/10642035


          Take a look on the documentation from stack overflow, to ensure you won't be losing points here:




          • Topics to as about: https://stackoverflow.com/help/on-topic

          • How to write a good question: https://stackoverflow.com/help/how-to-ask

          • What to avoid asking: https://stackoverflow.com/help/dont-ask

          • In case you decide to delete the question: https://stackoverflow.com/help/what-to-do-instead-of-deleting-question






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            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: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            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%2fstackoverflow.com%2fquestions%2f53395126%2fhow-to-predict-an-image-among-10-classes-instead-of-two-classes%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            -3














            Omar, my suggestion is for you to study a little further the libs you're using, such as Keras (mainly) and Numpy.



            This kind of question is going to be downvoted from users, because goes against the best practices from Stack Overflow, since you're asking for someone to give you the full code as an answer without looking out by yourself and detailing the specific challenge you're facing with which class, and not detailing the whole aspect of your code as well (such as the classifier object, which is not detailed where it came from, and guessing is not a good method to help here).



            Now, jumping to your problem, I suggest:




            1. Understand better the model from keras and its implications, on how to load models: https://keras.io/models/about-keras-models/

            2. Take a closer look on keras documentation and its methods
              https://keras.io/preprocessing/image/

            3. Take a look on this answer: https://stackoverflow.com/a/43470074/10642035


            Take a look on the documentation from stack overflow, to ensure you won't be losing points here:




            • Topics to as about: https://stackoverflow.com/help/on-topic

            • How to write a good question: https://stackoverflow.com/help/how-to-ask

            • What to avoid asking: https://stackoverflow.com/help/dont-ask

            • In case you decide to delete the question: https://stackoverflow.com/help/what-to-do-instead-of-deleting-question






            share|improve this answer


























              -3














              Omar, my suggestion is for you to study a little further the libs you're using, such as Keras (mainly) and Numpy.



              This kind of question is going to be downvoted from users, because goes against the best practices from Stack Overflow, since you're asking for someone to give you the full code as an answer without looking out by yourself and detailing the specific challenge you're facing with which class, and not detailing the whole aspect of your code as well (such as the classifier object, which is not detailed where it came from, and guessing is not a good method to help here).



              Now, jumping to your problem, I suggest:




              1. Understand better the model from keras and its implications, on how to load models: https://keras.io/models/about-keras-models/

              2. Take a closer look on keras documentation and its methods
                https://keras.io/preprocessing/image/

              3. Take a look on this answer: https://stackoverflow.com/a/43470074/10642035


              Take a look on the documentation from stack overflow, to ensure you won't be losing points here:




              • Topics to as about: https://stackoverflow.com/help/on-topic

              • How to write a good question: https://stackoverflow.com/help/how-to-ask

              • What to avoid asking: https://stackoverflow.com/help/dont-ask

              • In case you decide to delete the question: https://stackoverflow.com/help/what-to-do-instead-of-deleting-question






              share|improve this answer
























                -3












                -3








                -3






                Omar, my suggestion is for you to study a little further the libs you're using, such as Keras (mainly) and Numpy.



                This kind of question is going to be downvoted from users, because goes against the best practices from Stack Overflow, since you're asking for someone to give you the full code as an answer without looking out by yourself and detailing the specific challenge you're facing with which class, and not detailing the whole aspect of your code as well (such as the classifier object, which is not detailed where it came from, and guessing is not a good method to help here).



                Now, jumping to your problem, I suggest:




                1. Understand better the model from keras and its implications, on how to load models: https://keras.io/models/about-keras-models/

                2. Take a closer look on keras documentation and its methods
                  https://keras.io/preprocessing/image/

                3. Take a look on this answer: https://stackoverflow.com/a/43470074/10642035


                Take a look on the documentation from stack overflow, to ensure you won't be losing points here:




                • Topics to as about: https://stackoverflow.com/help/on-topic

                • How to write a good question: https://stackoverflow.com/help/how-to-ask

                • What to avoid asking: https://stackoverflow.com/help/dont-ask

                • In case you decide to delete the question: https://stackoverflow.com/help/what-to-do-instead-of-deleting-question






                share|improve this answer












                Omar, my suggestion is for you to study a little further the libs you're using, such as Keras (mainly) and Numpy.



                This kind of question is going to be downvoted from users, because goes against the best practices from Stack Overflow, since you're asking for someone to give you the full code as an answer without looking out by yourself and detailing the specific challenge you're facing with which class, and not detailing the whole aspect of your code as well (such as the classifier object, which is not detailed where it came from, and guessing is not a good method to help here).



                Now, jumping to your problem, I suggest:




                1. Understand better the model from keras and its implications, on how to load models: https://keras.io/models/about-keras-models/

                2. Take a closer look on keras documentation and its methods
                  https://keras.io/preprocessing/image/

                3. Take a look on this answer: https://stackoverflow.com/a/43470074/10642035


                Take a look on the documentation from stack overflow, to ensure you won't be losing points here:




                • Topics to as about: https://stackoverflow.com/help/on-topic

                • How to write a good question: https://stackoverflow.com/help/how-to-ask

                • What to avoid asking: https://stackoverflow.com/help/dont-ask

                • In case you decide to delete the question: https://stackoverflow.com/help/what-to-do-instead-of-deleting-question







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 20 at 15:04









                Luan Naufal

                5108




                5108






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • 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.


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





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • 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.


                    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%2fstackoverflow.com%2fquestions%2f53395126%2fhow-to-predict-an-image-among-10-classes-instead-of-two-classes%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

                    Costa Masnaga

                    Fotorealismo

                    Sidney Franklin