Created
May 14, 2018 14:29
-
-
Save ronzillia/e571f91c25e1202a73d0910ad89f26d2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# balance data via loss for each batch | |
x_train, y_train,index = batch_data | |
label=np.argmax(y_train,axis=1) | |
num_pos=np.count_nonzero(label) | |
num_neg=len(label)-num_pos | |
pos_weight=np.true_divide(num_neg+1,len(label)+1) | |
neg_weight=np.true_divide(num_pos+1,len(label)+1) | |
class_weight=np.array([[neg_weight,pos_weight]]) | |
# plus one to avoid all-zero and all-one problem | |
_ ,train_cost= sess.run([train_op,classification_loss_op], feed_dict={input_x: x_train,input_y_classification: y_train,bs_holder:batch_size,training_flag:True,tf_class_weight:class_weight}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment