Categories
Artificial Intelligence (AI) Development

How do I deal with an erratic validation set loss when the loss on my training set is monotonically decreasing?

Model used mobilenet_model = MobileNet(input_shape=in_dim, include_top=False, pooling=’avg’, weights=’imagenet’) mob_x = Dropout(0.75)(mobilenet_model.output) mob_x = Dense(2, activation=’sigmoid’)(mob_x) model = Model(mobilenet_model.input, mob_x) for layer in model.layers[:50]: layer.trainable=False for layer in model.layers[50:]: layer.trainable=True model.summary() The rest of the code train_datagen = ImageDataGenerator( rescale=1. / 255, shear_range=0.2, zoom_range=0.2, horizontal_flip=True) test_datagen = ImageDataGenerator(rescale=1./255) train_generator = train_datagen.flow_from_directory( ‘output/train’, # this is the […]

Categories
Development

how to reshape input image array from 1d to 3d

I have built the image classifier as bellow: import tensorflow as tf from tensorflow.keras.applications.mobilenet import preprocess_input image_width, image_height = 224, 224 input_shape = (image_width, image_height, 3) self.model = tf.keras.Sequential() pretrained_layer = tf.keras.applications.mobilenet.MobileNet( weights=”imagenet”, include_top=False, input_shape=self.input_shape ) self.model.add(pretrained_layer) self.model.add(tf.keras.layers.GlobalAveragePooling2D()) self.model.add(tf.keras.layers.Dense(256, activation=”relu”)) self.model.add(tf.keras.layers.Dropout(0.5)) self.model.add(tf.keras.layers.Dense(128, activation=”relu”)) self.model.add(tf.keras.layers.Dropout(0.2)) self.model.add(tf.keras.layers.Dense(len(DATA_LABELS), activation=”sigmoid”)) self.model.compile( optimizer=tf.keras.optimizers.Adam(0.0005), loss=”binary_crossentropy”, metrics=[“accuracy”], ) I also had a […]

Categories
Development

Failed to train with tf.keras.applications.MobileNetV2

Environment: TF2.0 Python 3.5 ubuntu 16.04 Problem: I try to use the pre-trained mobilenet_V2 but accuracy doesn’t increase: base_model = tf.keras.applications.MobileNetV2(input_shape=IMG_SHAPE, include_top=False, weights=’imagenet’) The script is copied from the tutorial of the tensorflow 2.0(https://www.tensorflow.org/tutorials/images/transfer_learning?hl=zh-cn) The only change I made is the dataset which feed into the network. The original code makes binary classification between dogs […]

Categories
Development

Adding layers to RESNET50 in order to build a JOIN CNN Model

This is my code in order to join resnet50 model with this model (that I want to train on my dataset). I want to freeze layers of the resnet50 model ( see Trainable=false) in the code . Here I’m importing resnet 50 model “ import tensorflow.keras import tensorflow as tf from tensorflow.keras.applications.resnet50 import ResNet50 from […]

Categories
Development

Tensorboard graph orphan layers

While building a model that includes transfer learning (from VGG-16). I encounter this strange behavior. Tensorboard graph shows the layers which are not part of the new model but part of the old, above the point of seperation, and they are just dangling there. When investigating further, model.summary() does not show these layers, model.get_layer(“block4_conv1”) can’t […]

Categories
Artificial Intelligence (AI) Development

Semantic issues with predictions made by my trained model

I’m new to Deep Learning. I used Keras and trained a inception_resnet_v2 model for my binary classification application (fire detection). As suggested from my previous question of a non-X class, I prepared a dataset of 8000 images of fire, and a larger dataset for non-fire (20,000 random images) to make sure the network also sees […]

Categories
Development

Unsure about Keras Functional API for fine-tuning

i’m learning about Keras and the usage of the functional API, specifically about using the pre-trained VGG16 model for another classification task, and i came across this piece of code: baseModel = VGG16(weights=”imagenet”, include_top=False, input_tensor=Input(shape=(224, 224, 3))) headModel=baseModel.output headModel=Flatten(name=”flatten”)(headModel) headModel=Dense(D, activation=”relu”)(headModel) headModel=Dropout(0.5)(headModel) headModel = Dense(classes, activation=”softmax”)(headModel) model = Model(inputs=baseModel.input, outputs=headModel) The last line, specifically the […]

Categories
Development

Transfer Learning with MobileV2Net

I am trying to implement transfer learning with MobileV2Net following from https://www.tensorflow.org/tutorials/images/transfer_learning . The above tutorial uses the MobileV2Net model as the base model and uses the “cats_vs_dog” dataset which has the type tensorflow.python.data.ops.dataset_ops._OptionsDataset. In my case i want to use MobileV2Net as the base model , freeze all the weights for different C.N.N layers,add […]

Categories
Development

Memory overflow during inference in tensorflow

I have written these functions to carryout inference using the saved weights of a trained binary classifier. I have about 120k images to make inference. But the GPU freezes after getting to 82k images. Please is there anything I need to fix in my code to resolve this memory issue. Could the model be saving […]

Categories
Ask

Keras image generator keep giving different number of lables

So I am trying to make a simple fine turned Resnet50 model using the Market1501 dataset and keras. So the data set contains images (12000 or so) and 751 lables that I want to use (0-750) I can fit the data into a single go so I have to use a image generator for this. […]