keras

Keras - Validation Loss and Accuracy stuck at 0

二次信任 提交于 2021-01-20 19:11:10
问题 I am trying to train a simple 2 layer Fully Connected neural net for Binary Classification in Tensorflow keras. I have split my data into Training and Validation sets with a 80-20 split using sklearn's train_test_split() . When I call model.fit(X_train, y_train, validation_data=[X_val, y_val]) , it shows 0 validation loss and accuracy for all epochs , but it trains just fine. Also, when I try to evaluate it on the validation set, the output is non-zero. Can someone please explain why I am

Keras - Validation Loss and Accuracy stuck at 0

爱⌒轻易说出口 提交于 2021-01-20 19:09:58
问题 I am trying to train a simple 2 layer Fully Connected neural net for Binary Classification in Tensorflow keras. I have split my data into Training and Validation sets with a 80-20 split using sklearn's train_test_split() . When I call model.fit(X_train, y_train, validation_data=[X_val, y_val]) , it shows 0 validation loss and accuracy for all epochs , but it trains just fine. Also, when I try to evaluate it on the validation set, the output is non-zero. Can someone please explain why I am

Share weights between two dense layers in keras

て烟熏妆下的殇ゞ 提交于 2021-01-20 18:20:52
问题 I have a code as follows. What I want to do is to share the same weights in two dense layers. The equation for op1 and op2 layer will be like that op1 = w1y1 + w2y2 + w3y3 + w4y4 + w5y5 + b1 op2 = w1z1 + w2z2 + w3z3 + w4z4 + w5z5 + b1 here w1 to w5 weights are shared between op1 and op2 layer inputs which are (y1 to y5) and (z1 to z5) respectively. ip_shape1 = Input(shape=(5,)) ip_shape2 = Input(shape=(5,)) op1 = Dense(1, activation = "sigmoid", kernel_initializer = "ones")(ip_shape1) op2 =

How to get intermediate outputs in TF 2.3 Eager with learning_phase?

两盒软妹~` 提交于 2021-01-20 09:46:18
问题 Example below works in 2.2; K.function is changed significantly in 2.3, now building a Model in Eager execution, so we're passing Model(inputs=[learning_phase,...]) . I do have a workaround in mind, but it's hackish, and lot more complex than K.function ; if none can show a simple approach, I'll post mine. from tensorflow.keras.layers import Input, Dense from tensorflow.keras.models import Model from tensorflow.python.keras import backend as K import numpy as np ipt = Input((16,)) x = Dense

keras.layers.TimeDistributed with hub.KerasLayer NotImplementedError

时光总嘲笑我的痴心妄想 提交于 2021-01-20 09:36:32
问题 I want to use tf.keras.TimeDistributed() layer with the tf.hub inception_v3 CNN model from the latest TensorFLow V2 version (tf-nightly-gpu-2.0-preview). The output is shown below. It seemst that tf.keras.TimeDistributed() is not fully implemented to work with tf.hub models. Somehow, the shape of the input layer cannot be computed. My question: Is there a workaround this problem? tf.keras.TimeDistributed with regular tf.keras.layer works fine. I just would like to apply the CNN model to each

keras.layers.TimeDistributed with hub.KerasLayer NotImplementedError

给你一囗甜甜゛ 提交于 2021-01-20 09:36:27
问题 I want to use tf.keras.TimeDistributed() layer with the tf.hub inception_v3 CNN model from the latest TensorFLow V2 version (tf-nightly-gpu-2.0-preview). The output is shown below. It seemst that tf.keras.TimeDistributed() is not fully implemented to work with tf.hub models. Somehow, the shape of the input layer cannot be computed. My question: Is there a workaround this problem? tf.keras.TimeDistributed with regular tf.keras.layer works fine. I just would like to apply the CNN model to each

GaussianDropout vs. Dropout vs. GaussianNoise in Keras

旧街凉风 提交于 2021-01-20 09:33:32
问题 Can anyone explain the difference between the different dropout styles? From the documentation, I assumed that instead of dropping some units to zero (dropout), GaussianDropout multiplies those units by some distribution. However, when testing in practice, all units are touched. The result looks more like the classic GaussianNoise. tf.random.set_seed(0) layer = tf.keras.layers.GaussianDropout(.05, input_shape=(2,)) data = np.arange(10).reshape(5, 2).astype(np.float32) print(data) outputs =

ValueError: Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: [8, 28, 28]

China☆狼群 提交于 2021-01-20 09:16:28
问题 I keep on getting this error related to input shape. Any help would be highly appreciated. Thanks! import tensorflow as tf (xtrain, ytrain), (xtest, ytest) = tf.keras.datasets.mnist.load_data() model = tf.keras.Sequential([ tf.keras.layers.Conv2D(16, kernel_size=3, activation='relu'), tf.keras.layers.MaxPooling2D(pool_size=2), tf.keras.layers.Conv2D(32, kernel_size=3, activation='relu'), tf.keras.layers.MaxPooling2D(pool_size=2), tf.keras.layers.Flatten(), tf.keras.layers.Dense(64, activation

Accuracy given from evaluating model not equal to sklearn classification_report accuracy

£可爱£侵袭症+ 提交于 2021-01-19 08:10:24
问题 I'm using sklearn classification_report for reporting test statistics. The accuracy given by this method is 42% while model evaluation gives 93% accuracy. Which one is the real accuracy and what's the reason of this difference? Model evaluation: results = model.evaluate(test_ds.values, test_lb.values) print(results) Output: 7397/7397 [==============================] - 0s 28us/sample - loss: 0.2309 - acc: 0.9305 Report Classification: import numpy as np from sklearn.metrics import

Accuracy given from evaluating model not equal to sklearn classification_report accuracy

梦想与她 提交于 2021-01-19 08:08:38
问题 I'm using sklearn classification_report for reporting test statistics. The accuracy given by this method is 42% while model evaluation gives 93% accuracy. Which one is the real accuracy and what's the reason of this difference? Model evaluation: results = model.evaluate(test_ds.values, test_lb.values) print(results) Output: 7397/7397 [==============================] - 0s 28us/sample - loss: 0.2309 - acc: 0.9305 Report Classification: import numpy as np from sklearn.metrics import