keras

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 =

How to change Sequential model to Custom Class model

可紊 提交于 2021-01-29 22:12:53
问题 I'm learning tensorflow 2.0 from its older versions. I found tensorflow model is changed Sequential-base from Class-base. But I want to use Class-base model because it is easy to read for me. I want to try translate : https://www.tensorflow.org/beta/tutorials/keras/basic_text_classification_with_tfhub embedding = 'https://tfhub.dev/google/tf2-preview/gnews-swivel-20dim/1' hub_layer = hub.KerasLayer(embedding, input_shape=[], dtype=tf.string, trainable=True) # hub_layer(train_example_batch[:3]

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,

Keras - ValueError: could not convert string to float

拈花ヽ惹草 提交于 2021-01-29 21:38:25
问题 I have the code shown below, but get the following error: ValueError: could not convert string to float: BRAF Provided that this is a sample of my data ( | is just a separator I added here for demonstration, you can imagine each value in a separate cell in a CSV file): c.401C>T | skin | 23:141905805-141905805 | 9947 | BRAF Could the strings be the issue? How can I read and pass strings in this case? from keras.models import Sequential from keras.layers import Dense from keras.models import

How to change Sequential model to Custom Class model

霸气de小男生 提交于 2021-01-29 21:15:09
问题 I'm learning tensorflow 2.0 from its older versions. I found tensorflow model is changed Sequential-base from Class-base. But I want to use Class-base model because it is easy to read for me. I want to try translate : https://www.tensorflow.org/beta/tutorials/keras/basic_text_classification_with_tfhub embedding = 'https://tfhub.dev/google/tf2-preview/gnews-swivel-20dim/1' hub_layer = hub.KerasLayer(embedding, input_shape=[], dtype=tf.string, trainable=True) # hub_layer(train_example_batch[:3]

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,

Keras - ValueError: could not convert string to float

丶灬走出姿态 提交于 2021-01-29 19:30:42
问题 I have the code shown below, but get the following error: ValueError: could not convert string to float: BRAF Provided that this is a sample of my data ( | is just a separator I added here for demonstration, you can imagine each value in a separate cell in a CSV file): c.401C>T | skin | 23:141905805-141905805 | 9947 | BRAF Could the strings be the issue? How can I read and pass strings in this case? from keras.models import Sequential from keras.layers import Dense from keras.models import

Yet another “Error when checking target: expected dense_2 to have shape (4,) but got array with shape (1,)”

三世轮回 提交于 2021-01-29 19:30:35
问题 I'm using Keras in Python 3. The issue I'm having seems to be similar to many others, and the best I can tell I might need to use Flatten(), though I am not seeing how to set the parameters correctly. I get the error: ValueError: Error when checking target: expected dense_2 to have shape (4,) but got array with shape (1,) My data is not of images (yet) but they are sequences I've turned in to data frames. model = Sequential() model.add(Dense(30, input_dim=16, activation='relu')) model.add

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 //

predict result for single record using keras model predict

笑着哭i 提交于 2021-01-29 18:51:11
问题 I have created model using Keras. Here is the associated code. - https://github.com/CVxTz/ECG_Heartbeat_Classification/blob/master/code/baseline_mitbih.py I could run it and get model accuracy. IT works as expect for train and test data. Now I Want to test with out sample record and get prediction result. How do I do this? My code - df_train = pd.read_csv("mitbih_train.csv", header=None) df_train = df_train.sample(frac=1) df_test = pd.read_csv("mitbih_test.csv", header=None) Y = np.array(df