Categories
Mastering Development

Tensorflow – Why loss not decrease when use custom loss function and model predict always the same class?

I’m writing a CNN with a custom loss function. If I use loss function of keras like categorical_crossentropy the loss decreasing, but if I use my custom loss function the loss not decrease and the model predict always the same class. Can anyone help me please? I insert below the code so you can understand […]

Categories
Mastering Development

tf.keras replace lower layer in pretrained resnet50

Is it possible to remove/replace the BOTTOM layers of a pretrained ResNet50 model in tf.keras.applications? For instance, I’ve tried doing this: import tensorflow as tf pretrained_resnet = tf.keras.applications.ResNet50(include_top=False, weights=’imagenet’) inputs = tf.keras.Input(shape=(256,256,1)) x = tf.keras.layers.ZeroPadding2D()(inputs) x = tf.keras.layers.Conv2D(filters=64, kernel_size=(7,7), strides=(2,2), padding=’same’)(x) outputs = pretrained_resnet.layers[3](x) test = tf.keras.Model(inputs, pretrained_resnet.output) But it gives this error: ValueError: Graph […]

Categories
Mastering Development

concatenate two input to one tensor keras expected axis -1 of input shape to have value 6 but received input with shape [5, 288, 288, 3]

I have two data inputs with the same shape for my U-net model. I have 2 (or more) images representing the same object but are using different types of cameras/images, e.g. night vision, thermal, rgb, etc. In such case I would just stack all the layers on top of each other and treat them as […]

Categories
Artificial Intelligence (AI) Mastering Development

How does MobileNet v1 achieve small parameter count on tensorflow?

Problem I was trying to re-build MobileNet model identical to the keras application provided version on Tensorflow v2.1.0. However, no matter what I tried (i.e., Conv2d, SeparableConv2D, DepthwiseConv2D), the parameter count seems way off to a point the model starts allocating 100+ GB ram in the system. The model summary for the keras version and […]

Categories
Mastering Development

VGG-19 Tensorflow 2.0 implementation

I am trying to implement VGG-19 CNN on CIFAR-10 dataset where the images are of dimension (32, 32, 3). The training set has 50000 images while the testing set has 10000 images. I am using Python 3.7 and TensorFlow 2.0. I have preprocessed the dataset by normalizing them- # Normalize the training and testing datasets- […]

Categories
Artificial Intelligence (AI) Mastering Development

DQN is unable to learn from image data

I am trying to write a DQN model that will be able to solve OpenAI gym CartPole environment. I successfully managed to do it using scalar observation data that env.step() returns. But I wanted to make a DQN that would learn from pixels so I made images returned by env.render(mode=’rgb_array’) as my states. Unfortunately I […]

Categories
Mastering Development

Tensorflow – adding Dropout layer increases inference time significantly

I have relatively small CNN model = tf.keras.models.Sequential([ tf.keras.layers.Conv2D(input_shape=(400,400,3), filters=6, kernel_size=5, padding=’same’, activation=’relu’), tf.keras.layers.Conv2D(filters=12, kernel_size=3, padding=’same’, activation=’relu’), tf.keras.layers.Conv2D(filters=24, kernel_size=3, strides=2, padding=’valid’, activation=’relu’), tf.keras.layers.Conv2D(filters=32, kernel_size=3, strides=2, padding=’valid’, activation=’relu’), tf.keras.layers.Conv2D(filters=48, kernel_size=3, strides=2, padding=’valid’, activation=’relu’), tf.keras.layers.Conv2D(filters=64, kernel_size=3, strides=2, padding=’valid’, activation=’relu’), tf.keras.layers.Conv2D(filters=96, kernel_size=3, strides=2, padding=’valid’, activation=’relu’), tf.keras.layers.Conv2D(filters=128, kernel_size=3, strides=2, padding=’valid’, activation=’relu’), tf.keras.layers.Flatten(), tf.keras.layers.Dense(256, activation=’relu’), tf.keras.layers.Dense(256, activation=’relu’), tf.keras.layers.Dense(256, activation=’relu’), tf.keras.layers.Dense(240, […]

Categories
Mastering Development

Python Keras: Unable to load model with a custom layer although it has get_config

I used a custom layer for my Keras model, namely the DepthwiseConv3D layer. I trained the model and saved it using model.save(“model.h5″) from DepthwiseConv3D import DepthwiseConv3D model = load_model(‘model.h5’, custom_objects={‘DepthwiseConv3D’: DepthwiseConv3D}) But I am getting “TypeError: unorderable types: NoneType() > int()”, raised by DepthWiseConv3D at: if (self.groups > self.input_dim): raise ValueError(‘The number of groups cannot […]

Categories
Mastering Development

tensorflow v2.1 training DCGAN using tf.keras failed, what happend?

I want to use tensorflow.keras (ver 2.1) to train DCGAN. When I followed official tutorial (https://www.tensorflow.org/tutorials/generative/dcgan), official code is trained successfully. However, when I tried to rewrite like below, training result failed. The result looks noise and loss is almost samle value regardless of training iterations. I do not know what caused… %tensorflow_version 2.x import […]

Categories
Mastering Development

I followed the tensorflow image segmentation tutorial, but the predicted mask is blank

I’d like to try image segmentation with my grayscale tif images (the shape of original images are (512,512) and the value of each pixel is between 0-2 or nan which is in float32 type and the mask images have 0, 1, or nan also in float32 type). I followed Google Colab and tensorflow tutorialto create […]