keras

Shapes for training data and labels

Shapes for training data and labels Question: I am trying to train a convolutional neural network using Conv1D and sparse_categorical_crossentropy as a loss function but I keep having problems related to the shapes of the data. Here is the network: model=models.Sequential() model=tf.keras.models.Sequential([ tf.keras.layers.Conv1D(16, 24, input_shape=(1000, 4), activation="relu"), tf.keras.layers.MaxPooling1D(pool_size=24, strides=24), tf.keras.layers.Conv1D(8, 8, activation="relu"), tf.keras.layers.MaxPooling1D(pool_size=8, strides=8), tf.keras.layers.Flatten(), …

Total answers: 1

WARNING:tensorflow:Early stopping conditioned on metric `val_loss` which is not available. Available metrics are: loss,recall

WARNING:tensorflow:Early stopping conditioned on metric `val_loss` which is not available. Available metrics are: loss,recall Question: I have the error in the title when running the code below: def create_model(learning_rate, dropout, l2_lambda): model = Sequential() model.add(Dense(128,input_dim=X_train.shape[1], activation=’relu’, kernel_regularizer=regularizers.l2(l2_lambda))) model.add(BatchNormalization()) model.add(Dropout(dropout)) model.add(Dense(64, activation=’relu’, kernel_regularizer=regularizers.l2(l2_lambda))) model.add(Dropout(dropout)) model.add(Dense(1, activation=’sigmoid’)) optimizer = Adam(learning_rate=learning_rate) model.compile(loss=’binary_crossentropy’, optimizer=optimizer, metrics=[‘Recall’]) return model early_stopping = …

Total answers: 1

x and y must have same first dimension, but have shapes (9,) and (4,)

x and y must have same first dimension, but have shapes (9,) and (4,) Question: y_pred = fig.predict(x.reshape(1, -1)).reshape(-1) colors_dark = ["#1F1FIF", "#313131", "#636363", "#AEAEAE", "#DADADA"] colors_red = ["#331313", "#582626", "#9E1717", "#D35151", "#E9B4B4"] colors_green=[ "# 01411C", "#4B6F44", "#4F7942", "#74C365", "#D0F0C0"] filterwarnings("ignore") epochs =[ i for i in range(9)] fig, ax = plt.subplots(1, 2,figsize=(14,7)) train_acc1 = …

Total answers: 1

Check whether a variable is instance of ResNet50

Check whether a variable is instance of ResNet50 Question: I am checking whether model = ResNet50(weights=’imagenet’, include_top=False, pooling="avg") is instance of keras.applications.ResNet50 What I have done is: isinstance(model, ResNet50) but unfortunately this is raising me the following exception: TypeError: isinstance() arg 2 must be a type, a tuple of types, or a union Moreover, I …

Total answers: 1

predicting data bug with keras

predicting data bug with keras Question: Hi im trying to build a model in keras that can predict some data based on training values. I’ve seen this work succesfully all over the internet but my example code doesn’t work: from keras.models import Sequential from keras.layers import Dense, Activation import numpy as np model = Sequential() …

Total answers: 1

tf keras autokeras with early stopping returns empty history

tf keras autokeras with early stopping returns empty history Question: I am trying different models for the same dataset, being autokeras.ImageClassifier one of them. First I go for img_size = (100,120,3) train_dataset = get_dataset(x_train, y_train, img_size[:-1], 128) valid_dataset = get_dataset(x_valid, y_valid, img_size[:-1], 128) test_dataset = get_dataset(x_test, y_test, img_size[:-1], 128) For getting the dataset with a …

Total answers: 1

epoch taking too long,

epoch taking too long, Question: I have a good pc with good memory (intel core i7-11th gen, and 16gb of ram) still each of my epochs are taking about 1,5 hour, is it normal to take this long? from keras.models import Sequential from keras.layers import Dense from keras.layers import LSTM # define model model = …

Total answers: 1

Activity regularizer in Keras: before or after activation?

Activity regularizer in Keras: before or after activation? Question: Suppose I have: output = Dense(units=12, activation=’sigmoid’, activity_regularizer=L1(1e-2))(input) Keras documentation says activity regularizer "apply a penalty on the layer’s output", but it does not specify whether "output" means the output of the dense operation only, or that of the entire layer including activation. For my problem …

Total answers: 2

Python Parallel Processing with ThreadPoolExecutor Gives Wrong Results with Keras Model

Python Parallel Processing with ThreadPoolExecutor Gives Wrong Results with Keras Model Question: I am using parallel processing using the concurrent.futures.ThreadPoolExecutor class to make multiple predictions using a Keras model for different sets of weights. But the Keras model predictions using parallel processing are not correct. This is a reproducible sample code that creates 10 sets …

Total answers: 1