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
$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.
machine-learning tensorflow convnet
$endgroup$
add a comment |
$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.
machine-learning tensorflow convnet
$endgroup$
add a comment |
$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.
machine-learning tensorflow convnet
$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
machine-learning tensorflow convnet
asked 18 mins ago
AnshulKapoorAnshulKapoor
31
31
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
$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)
$endgroup$
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
$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)
$endgroup$
add a comment |
$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)
$endgroup$
add a comment |
$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)
$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)
answered just now
m0nzderrm0nzderr
363
363
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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