Weighted samples in Tensorflow for convolutional neural networksRetrain final layer of Inception modelBinary classification of similar images with small region of interestmultiple digit detectionTensorFlow: Regression using Deep Neural NetworkDesign strategies for higher resolution images for Convolutional neural network?Structure of Convolutional Neural Network to analyze a sequence of framesHybrid Convolutional and Conventional Neural NetworksTensorflow CNN sometimes converges, sometimes notMulti-input Convolutional Neural Network for Images ClassificationFully convolutional networks with partially segmented data

Calculate Pi using Monte Carlo

C++ lambda syntax

Extract substring according to regexp with sed or grep

Checking @@ROWCOUNT failing

Center page as a whole without centering each element individually

categorizing a variable turns it from insignificant to significant

What's the meaning of "what it means for something to be something"?

What is it called when someone votes for an option that's not their first choice?

Does capillary rise violate hydrostatic paradox?

Magnifying glass in hyperbolic space

"Marked down as someone wanting to sell shares." What does that mean?

Weird lines in Microsoft Word

Offset in split text content

Writing in a Christian voice

What is the meaning of "You've never met a graph you didn't like?"

How can I, as DM, avoid the Conga Line of Death occurring when implementing some form of flanking rule?

Why is indicated airspeed rather than ground speed used during the takeoff roll?

Derivative of an interpolated function

Is divisi notation needed for brass or woodwind in an orchestra?

Taking the numerator and the denominator

Why didn’t Eve recognize the little cockroach as a living organism?

How to preserve electronics (computers, ipads, phones) for hundreds of years?

Do I have to take mana from my deck or hand when tapping this card?

How do you justify more code being written by following clean code practices?



Weighted samples in Tensorflow for convolutional neural networks


Retrain final layer of Inception modelBinary classification of similar images with small region of interestmultiple digit detectionTensorFlow: Regression using Deep Neural NetworkDesign strategies for higher resolution images for Convolutional neural network?Structure of Convolutional Neural Network to analyze a sequence of framesHybrid Convolutional and Conventional Neural NetworksTensorflow CNN sometimes converges, sometimes notMulti-input Convolutional Neural Network for Images ClassificationFully convolutional networks with partially segmented data













0












$begingroup$


For my binary classification problem (A vs B), each image in either class has its individual weight. This means, for example, if I have 10000 images for A, not all of the images are equally important. Weight of "0.9" would mean it is very important, and a weight of "0.01" means that it is not that important.



Can this information be communicated to the training in Tensorflow?



Thanks for the help.










share|improve this question









$endgroup$
















    0












    $begingroup$


    For my binary classification problem (A vs B), each image in either class has its individual weight. This means, for example, if I have 10000 images for A, not all of the images are equally important. Weight of "0.9" would mean it is very important, and a weight of "0.01" means that it is not that important.



    Can this information be communicated to the training in Tensorflow?



    Thanks for the help.










    share|improve this question









    $endgroup$














      0












      0








      0





      $begingroup$


      For my binary classification problem (A vs B), each image in either class has its individual weight. This means, for example, if I have 10000 images for A, not all of the images are equally important. Weight of "0.9" would mean it is very important, and a weight of "0.01" means that it is not that important.



      Can this information be communicated to the training in Tensorflow?



      Thanks for the help.










      share|improve this question









      $endgroup$




      For my binary classification problem (A vs B), each image in either class has its individual weight. This means, for example, if I have 10000 images for A, not all of the images are equally important. Weight of "0.9" would mean it is very important, and a weight of "0.01" means that it is not that important.



      Can this information be communicated to the training in Tensorflow?



      Thanks for the help.







      machine-learning tensorflow convnet






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 18 mins ago









      AnshulKapoorAnshulKapoor

      31




      31




















          1 Answer
          1






          active

          oldest

          votes


















          0












          $begingroup$

          Weighted loss function is what you need.



          If you use Tensorflow with Keras, you can simply use the class_weight argument of the fit function (e.g., model.fit(..., class_weight = 0: .9, 1: .1)).



          As an alternative, you could just implement your own weighted loss function. For example:




          CLASS_1_WEIGHT = .9
          CLASS_0_WEIGHT = .1

          def weighted_bce(y_true, y_pred):
          w = y_true*CLASS_1_WEIGHT+ (1.0 - y_true)*CLASS_0_WEIGHT
          return K.mean(K.binary_crossentropy(y_true, y_pred) * w, axis=-1)





          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%2f47642%2fweighted-samples-in-tensorflow-for-convolutional-neural-networks%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









            0












            $begingroup$

            Weighted loss function is what you need.



            If you use Tensorflow with Keras, you can simply use the class_weight argument of the fit function (e.g., model.fit(..., class_weight = 0: .9, 1: .1)).



            As an alternative, you could just implement your own weighted loss function. For example:




            CLASS_1_WEIGHT = .9
            CLASS_0_WEIGHT = .1

            def weighted_bce(y_true, y_pred):
            w = y_true*CLASS_1_WEIGHT+ (1.0 - y_true)*CLASS_0_WEIGHT
            return K.mean(K.binary_crossentropy(y_true, y_pred) * w, axis=-1)





            share









            $endgroup$

















              0












              $begingroup$

              Weighted loss function is what you need.



              If you use Tensorflow with Keras, you can simply use the class_weight argument of the fit function (e.g., model.fit(..., class_weight = 0: .9, 1: .1)).



              As an alternative, you could just implement your own weighted loss function. For example:




              CLASS_1_WEIGHT = .9
              CLASS_0_WEIGHT = .1

              def weighted_bce(y_true, y_pred):
              w = y_true*CLASS_1_WEIGHT+ (1.0 - y_true)*CLASS_0_WEIGHT
              return K.mean(K.binary_crossentropy(y_true, y_pred) * w, axis=-1)





              share









              $endgroup$















                0












                0








                0





                $begingroup$

                Weighted loss function is what you need.



                If you use Tensorflow with Keras, you can simply use the class_weight argument of the fit function (e.g., model.fit(..., class_weight = 0: .9, 1: .1)).



                As an alternative, you could just implement your own weighted loss function. For example:




                CLASS_1_WEIGHT = .9
                CLASS_0_WEIGHT = .1

                def weighted_bce(y_true, y_pred):
                w = y_true*CLASS_1_WEIGHT+ (1.0 - y_true)*CLASS_0_WEIGHT
                return K.mean(K.binary_crossentropy(y_true, y_pred) * w, axis=-1)





                share









                $endgroup$



                Weighted loss function is what you need.



                If you use Tensorflow with Keras, you can simply use the class_weight argument of the fit function (e.g., model.fit(..., class_weight = 0: .9, 1: .1)).



                As an alternative, you could just implement your own weighted loss function. For example:




                CLASS_1_WEIGHT = .9
                CLASS_0_WEIGHT = .1

                def weighted_bce(y_true, y_pred):
                w = y_true*CLASS_1_WEIGHT+ (1.0 - y_true)*CLASS_0_WEIGHT
                return K.mean(K.binary_crossentropy(y_true, y_pred) * w, axis=-1)






                share











                share


                share










                answered just now









                m0nzderrm0nzderr

                363




                363



























                    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%2f47642%2fweighted-samples-in-tensorflow-for-convolutional-neural-networks%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

                    Ружовы пелікан Змест Знешні выгляд | Пашырэнне | Асаблівасці біялогіі | Літаратура | НавігацыяДагледжаная версіяправерана1 зменаДагледжаная версіяправерана1 змена/ 22697590 Сістэматыкана ВіківідахВыявына Вікісховішчы174693363011049382

                    ValueError: Error when checking input: expected conv2d_13_input to have shape (3, 150, 150) but got array with shape (150, 150, 3)2019 Community Moderator ElectionError when checking : expected dense_1_input to have shape (None, 5) but got array with shape (200, 1)Error 'Expected 2D array, got 1D array instead:'ValueError: Error when checking input: expected lstm_41_input to have 3 dimensions, but got array with shape (40000,100)ValueError: Error when checking target: expected dense_1 to have shape (7,) but got array with shape (1,)ValueError: Error when checking target: expected dense_2 to have shape (1,) but got array with shape (0,)Keras exception: ValueError: Error when checking input: expected conv2d_1_input to have shape (150, 150, 3) but got array with shape (256, 256, 3)Steps taking too long to completewhen checking input: expected dense_1_input to have shape (13328,) but got array with shape (317,)ValueError: Error when checking target: expected dense_3 to have shape (None, 1) but got array with shape (7715, 40000)Keras exception: Error when checking input: expected dense_input to have shape (2,) but got array with shape (1,)

                    Illegal assignment from SObject to ContactFetching String, Id from Map - Illegal Assignment Id to Field / ObjectError: Compile Error: Illegal assignment from String to BooleanError: List has no rows for assignment to SObjectError on Test Class - System.QueryException: List has no rows for assignment to SObjectRemote action problemDML requires SObject or SObject list type error“Illegal assignment from List to List”Test Class Fail: Batch Class: System.QueryException: List has no rows for assignment to SObjectMapping to a user'List has no rows for assignment to SObject' Mystery