deep-learning

How to balance dataset using fit_generator() in Keras?

匆匆过客 提交于 2021-02-02 09:23:57
问题 I am trying to use keras to fit a CNN model to classify 2 classes of data . I have imbalanced dataset I want to balance the data. I don't know can I use class_weight in model.fit_generator . I wonder if I used class_weight="balanced" in model.fit_generator The main code : def generate_arrays_for_training(indexPat, paths, start=0, end=100): while True: from_=int(len(paths)/100*start) to_=int(len(paths)/100*end) for i in range(from_, int(to_)): f=paths[i] x = np.load(PathSpectogramFolder+f) x =

How to balance dataset using fit_generator() in Keras?

我只是一个虾纸丫 提交于 2021-02-02 09:22:10
问题 I am trying to use keras to fit a CNN model to classify 2 classes of data . I have imbalanced dataset I want to balance the data. I don't know can I use class_weight in model.fit_generator . I wonder if I used class_weight="balanced" in model.fit_generator The main code : def generate_arrays_for_training(indexPat, paths, start=0, end=100): while True: from_=int(len(paths)/100*start) to_=int(len(paths)/100*end) for i in range(from_, int(to_)): f=paths[i] x = np.load(PathSpectogramFolder+f) x =

AttributeError: 'Tensor' object has no attribute '_keras_history' using CRF

牧云@^-^@ 提交于 2021-01-29 21:42:09
问题 I know there are a bunch of questions on this problem and I have read some of those but none of them worked for me. I am trying to build a model with the following architecture: The code is as follows: token_inputs = Input((32,), dtype=tf.int32, name='input_ids') mask_inputs = Input((32,), dtype=tf.int32, name='attention_mask') seg_inputs = Input((32,), dtype=tf.int32, name='token_type_ids') seq_out, _ = bert_model([token_inputs, mask_inputs, seg_inputs]) bd = Bidirectional(LSTM(units=50,

AttributeError: 'Tensor' object has no attribute '_keras_history' using CRF

◇◆丶佛笑我妖孽 提交于 2021-01-29 19:58:30
问题 I know there are a bunch of questions on this problem and I have read some of those but none of them worked for me. I am trying to build a model with the following architecture: The code is as follows: token_inputs = Input((32,), dtype=tf.int32, name='input_ids') mask_inputs = Input((32,), dtype=tf.int32, name='attention_mask') seg_inputs = Input((32,), dtype=tf.int32, name='token_type_ids') seq_out, _ = bert_model([token_inputs, mask_inputs, seg_inputs]) bd = Bidirectional(LSTM(units=50,

I got value error that image has no shape while converting image to tensor for performing neural style transfer

岁酱吖の 提交于 2021-01-29 19:26:33
问题 I am using tensorflow_hub modules to perform neural style transfer and I get the error "'images' contains no shape". I don't understand where I made a mistake. This is my code: import tensorflow_hub as hub import tensorflow as tf import numpy as np import matplotlib.pyplot as plt content_path = r'C:\Users\Sriram\Desktop\efil.jpg' style_path = r'C:\Users\Sriram\Desktop\download1.jfif' content_image = plt.imread(content_path) style_image = plt.imread(style_path) plt.subplot(1, 2, 1) plt.title(

InvalidArgumentError: 2 root error(s) found. (0) Invalid argument: Incompatible shapes: [4,3] vs. [4,4]

六月ゝ 毕业季﹏ 提交于 2021-01-29 18:54:42
问题 I am facing below error when trying to train a multi-class classification model ( 4 classes) for Image dataset. Even though my output tensor is of shape 4 I am facing below issue. Please let me know how to fix this issue. Epoch 1/10 --------------------------------------------------------------------------- InvalidArgumentError Traceback (most recent call last) <ipython-input-30-01c6f78f4d4f> in <module> 4 epochs=epochs, 5 validation_data=val_data_gen, ----> 6 validation_steps=total_val //

What to do next when Deep Learning neural network stop improving in term of validation accuracy?

余生长醉 提交于 2021-01-29 18:31:31
问题 I was running into this issue where my model converge very fast only after about 20 or 30 epoch My data set contain 7000 sample and my neural network has 3 hidden layer, each with 18 neurons and batch normalization with drop out 0.2. My task is a multi label classification where my label are [0 0 1] , [0 1 0], [1 0 0] and [0 0 0] num_neuron = 18 model = Sequential() model.add(Dense(num_neuron, input_shape=(input_size,), activation='elu')) model.add(Dropout(0.2)) model.add(keras.layers

Is it possible to see the output after Conv2D layer in Keras

一曲冷凌霜 提交于 2021-01-29 16:24:23
问题 I am trying to understand each layer of Keras while implementing CNN. In Conv2D layer i understand that it creates different convolution layer depending on various feature map values. Now, My question is that Can i see different feature map matrix that are applied on input image to get the convolution layer Can i see the value of matrix that is generated after completion of Conv2D step. Thanks in advance 回答1: You can get the output of a certain convolutional layer in this way: import keras

How can i add a Bi-LSTM layer on top of bert model?

大憨熊 提交于 2021-01-29 15:22:30
问题 I'm using pytorch and I'm using the base pretrained bert to classify sentences for hate speech. I want to implement a Bi-LSTM layer that takes as an input all outputs of the latest transformer encoder from the bert model as a new model (class that implements nn.Module ), and i got confused with the nn.LSTM parameters. I tokenized the data using bert = BertForSequenceClassification.from_pretrained("bert-base-uncased", num_labels=int(data['class'].nunique()),output_attentions=False,output

how to call opencv functions in tensorflow(python)?

那年仲夏 提交于 2021-01-29 15:13:32
问题 when I train the model,I have customized a loss function.The calculation of the loss value in this function requires the function of opencv.See the code,but I get a wrong.I don't know how to solve it,someone can help me?Thanks a lot. #this is my loss function def instance_loss_function(predict,label): best_match_label_image=search_MaxPixelAccuracy_permutation(predict_convert_gray_image(predict),label) predict_image=predict loss_sum=0.0 best_match_label_image_contours_number=len(cv2