Categories
Mastering Development

R Keras – multiclass classification accuracy and validation stuck at near zero

I am teaching myself the keras framework and I am trying to train a neural network on the IMDBWIKI faces data set using R. I configured a python environment with python3.8 and keras 2.4.3 and tensor flow 2.3.1 and other prerequisites. I went through a series of steps pre-processing the "mat" files provided with both […]

Categories
Mastering Development

Boolean Labels Training with Keras causes the error “Please provide data which shares the same first dimension”

So, here is what I am trying to do. My model has to receive a number of training samples, each a conjunction of Boolean literals (i.e. a vector of 0 or 1s) assigned with a truth value. Learning from the samples, it must be able to receive some test vector and determine its truth value. […]

Categories
Artificial Intelligence (AI) Mastering Development

How can I create a network that takes a single digit as an input and outputs a 2D array?

I want to create a network that can take a single digit (float) and then output a 2D array. I’m using TensorFlow in Python and so far I have this for my model and training. i = Input(shape=(1,)) x = Dense(512, activation=’relu’)(i) x = Dropout(0.2)(x) x = Dense(K, activation=’softmax’)(x) model = Model(i, x) model.compile(optimizer=’adam’, loss=’sparse_categorical_crossentropy’, […]

Categories
Mastering Development

How to stop Keras from sharing weights/layers between different models?

I am using 10fold-validation to assess how well the model generalizes for unseen data. For that I have to create multiple models with the same layers structure and compile params. When the 10fold-validation process starts, I noticed that multiple models use shared weights/layers while I want to train the different model all over again ( […]

Categories
Artificial Intelligence (AI) Mastering Development

Flattened input layer shape

The code below was taken from TensorFlow in Practice by deeplearning.ai course in Coursera (computer vision example – week 2). import tensorflow as tf mnist = tf.keras.datasets.fashion_mnist (training_images, training_labels), (test_images, test_labels) = mnist.load_data() training_images = training_images / 255.0 test_images = test_images / 255.0 model = tf.keras.models.Sequential([tf.keras.layers.Flatten(), tf.keras.layers.Dense(128, activation=tf.nn.relu), tf.keras.layers.Dense(10, activation=tf.nn.softmax)]) model.compile(optimizer=tf.optimizers.Adam(), loss=’sparse_categorical_crossentropy’, metrics=[‘accuracy’]) print("Executing Training:") […]

Categories
Mastering Development

Estimator should be an estimator implementing ‘fit’ method – error

I am just trying to implement Cross Validation to MLP but this error doesn’t let me go model = keras.Sequential([ keras.layers.Dense(150,input_dim=21, activation=’relu’), keras.layers.Dense(100, activation=’relu’), keras.layers.Dense(50, activation=’relu’), keras.layers.Dense(24,activation=’softmax’) ]) model.compile(optimizer=opt2, loss=’sparse_categorical_crossentropy’, metrics=[‘accuracy’]) MLP = model.fit(X_train, Y_train,epochs=20) scores_ = cross_val_score(model, X, y, cv=5) print("scores = ",scores_)

Categories
Artificial Intelligence (AI) Mastering Development

CIFAR-10 can’t get above 10% Accuracy with MobileNet, VGG16 and ResNet on Keras

I’m trying to train the most popular Models (mobileNet, VGG16, ResNet…) with the CIFAR10-dataset but the accuracy can’t get above 9,9%. I want to do that with the completely model (include_top=True) and without the weights from imagenet. I have tried increasing/decreasing dropout and learning rate and I changed the optimizers but I become always the […]

Categories
Mastering Development

Model-building function did not return a valid Keras Model instance, found

Hi i am trying to learn CNN following Krish naik Youtube tutorial in one program i am getting that error please help me my code is given below import keras.datasets fashion=keras.datasets.fashion_mnist (x_train,y_train),(x_test,y_test)=fashion.load_data() x_train=x_train/255.00 x_test=x_test/255.00 x_train=x_train.reshape(x_train.shape[0],x_train.shape[1],x_train.shape[2],1) x_test=x_test.reshape(x_test.shape[0],x_test.shape[1],x_test.shape[2],1) from keras.models import Sequential from keras.layers import Conv2D,Flatten,Dropout,Dense from keras.optimizers import Adam def build_knn(hp): models=Sequential() models.add(Conv2D(filters=hp.Int(‘conv2d_1’,min_value=32,max_value=128,step=16), kernel_size=hp.Choice(‘conv1_kernal’,values=[3,5]), activation=’relu’, input_shape=(28,28,1) […]

Categories
Mastering Development

Multiple output values on tensorflow [closed]

I want to make a tensorflow model that would return me 14400 values. I have input of shape (1, 7854) and output of shape (1, 14400). Using this data I get error: ValueError: Can not squeeze dim[1], expected a dimension of 1, got 14400 for ‘metrics/accuracy/Squeeze’ (op: ‘Squeeze’) with input shapes: [?,14400]. My code is: […]

Categories
Artificial Intelligence (AI) Development

Trouble with EarlyStopping in tf.keras

I am training my first transferred learning model(yay!) and I am having trouble getting the model to stop training when the validation loss hasn’t changed by more than 0.1 in more than 3 epochs. Here is the relevant block of code early_stopping = tf.keras.callbacks.EarlyStopping(monitor=’val_loss’, patience=3, min_delta = 0.1) model.compile(optimizer=’adam’, loss=’sparse_categorical_crossentropy’, metrics=[‘accuracy’], callbacks=[early_stopping]) EPOCHS = 100 […]