resnet50 implementation for semantic segmentation

I am new to resnet models. I want to implement a resnet50 model for semantic segmentation I am following the code from this video, but my numclasses is 21. I have a few questions: If i pass in any rgb jpeg image into the model, I get an output of size (1, 21). What does this output represent? Since I am doing semantic segmentation, my images dont have any rgb channels, so what should I put for image_channels in self.conv1? …
Category: Data Science

How to match the input image with the ground truth image (the order)

I'm a beginner learning deep learning and trying to do semantic segmentation problems on histologic image using python and TensorFlow. There is 2 main file : Images.npy and Labels.npy (Ground truth). So before the training, i want to match the input images with the ground truth images. So, the ground truth will be matched with the images. For Example : There is images_1 and labels_1. When we check labels_1 is match with images_1 (Matched). I want to avoid this condition …
Category: Data Science

semantic segmentation using kmeans or mean shift

i know what semantic segmentation is and i know how to do semantic segmentation using deep learning but my question here can i do semantic segmentation with a traditional way like kmeans or mean shift ckustering? here's what i tried to do import numpy as np import cv2 from sklearn.cluster import MeanShift, estimate_bandwidth #from skimage.color import rgb2lab #Loading original image originImg = cv2.imread('test/2019_00254.jpg') # Shape of original image originShape = originImg.shape # Converting image into array of dimension [nb of …
Category: Data Science

Which F1-score is used for the semantic segmentation tasks?

I read some papers about state-of-the-art semantic segmentation models and in all of them, authors use for comparison F1-score metric, but they did not write whether they use the "micro" or "macro" version of it. Does anyone know which F1-score is used to describe the segmentation results and why it is so obvious that authors do not define it in papers? Sample papers: https://arxiv.org/pdf/1709.00201.pdf https://arxiv.org/pdf/1511.00561.pdf
Category: Data Science

At the first epochs, what will segmentation model get?

I am working at a semantic segmentation problem now, with 5-classes task. But when I running on validation function and output my probablities map. I found that with the background class (the extra class for nnUNet, named class-0), the probalities always up to nearly 1, even when running on much epochs. But the other foreground classes (as class-1 to class-6), probalities can't range to 1.0 the highest. But at least that I can recognize the outline of the target, but …
Category: Data Science

Tensorflow 2 Semantic Segmentation - loss function for two classes

I am trying to implement a U-net for semantic segmentation with two classes (foreground=1 and background=0) in the segmentation mask images, following this tutorial. They have used SparseCategoricalCrossentropy for OUTPUT_CLASSES = 3, as shown below: OUTPUT_CLASSES = 3 model = unet_model(output_channels=OUTPUT_CLASSES) model.compile(optimizer='adam', loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True), metrics=['accuracy']) EPOCHS = 20 VAL_SUBSPLITS = 5 VALIDATION_STEPS = info.splits['test'].num_examples//BATCH_SIZE//VAL_SUBSPLITS model_history = model.fit(train_batches, epochs=EPOCHS, steps_per_epoch=STEPS_PER_EPOCH, validation_steps=VALIDATION_STEPS, validation_data=test_batches, callbacks=[DisplayCallback()]) If I use the same network with OUTPUT_CLASSES = 2 the training loss is NaN. What should I use …
Category: Data Science

How to create the categorical mask for images specifically for Tensor? Or port the NumPy function correctly to Dataset.map function

I'm trying to move from NumPy array as my dataset to tensorflow.Dataset. Now, I've created a pipeline to train the model for classification problems. At some point, I just normalize all the images using map function: dataset['train'] = dataset['train'].map(pre_pr, num_parallel_calls=tf.data.experimental.AUTOTUNE) And the function description looks like this: @tf.function def normalize(input_image: tf.Tensor, input_mask: tf.Tensor) -> tuple: input_image = tf.cast(input_image, tf.float32) / 255.0 input_mask= tf.cast(input_mask, tf.float32) / 255.0 return input_image, input_mask @tf.function def pre_pr(datapoint: dict) -> tuple: input_image = tf.image.resize(datapoint['image'], (IMG_SIZE, IMG_SIZE)) …
Category: Data Science

Identify visible stones in the image - Approach in OpenCV & Deeplearning

I have samples images of stones present in the images. I need to identify the visible stones only. The approach which I tried is threshold based filtering and detecting cv2.contours. Also, I am looking into ENet Architecture for semantic segmentation based deep learning approach. The samples images are below. Example image1: Example image2: The code which I tried for contour based detection is as below image = cv2.imread(os.path.join(img_path, img_name2)) # threshold based customization lower_bound = np.array([0, 0, 0]) upper_bound = …
Category: Data Science

My semantic segmentation model classifies everything as background

So, I am working on a semantic segmentation task using U-Net. The dataset is very unbalanced, with the background being by far the most common, and the last class being very scarce. First I trained it using Categorical Cross Entropy as the loss function, and in the end it simply classified everything as background (I used IoU as a measurement of success, and the confusion matrix had non-null values only on the first column, which can only mean that). I …
Category: Data Science

U-Net for Crack Segmentation

I used a U-Net model that was built for Oxford Pet Segmentation to a crack segmentation project. Without transfer learning, model works fine for pet segmentation but not for crack segmentation. What could be the reason? I know there are codes for Crack Segmentation with U-Net but I want to learn why the code for pet doesn't work well for crack. Thanks in advance. def double_conv_block(x,n_filters): x=layers.Conv2D(n_filters,3,padding="same",activation="relu",kernel_initializer="he_normal")(x) x=layers.Conv2D(n_filters,3,padding="same",activation="relu",kernel_initializer="he_normal")(x) return x def downsample_block(x,n_filters): f=double_conv_block(x,n_filters) p=layers.MaxPool2D(2)(f) p=layers.Dropout(0.3)(p) return f,p def upsample_block(x,conv_features,n_filters): x=layers.Conv2DTranspose(n_filters,3,2,padding="same")(x) …
Category: Data Science

Multiclass semantic segmentation with some classes possibly not present in some of the images

Let's assume we have a large annotated dataset with 4 classes. In this dataset, there might be annotated images with less than 4 classes, where the remaining classes might or might not be present. As an example, say we want to detect pedestrians/cars/bicycles/roads in images. In our dataset, there are some annotated images with only 3 classes: pedestrians/cars/bicycles, but this does not mean there are no roads in these images. That is, there might be roads in these images that …
Category: Data Science

Correct way of computing dice score for image segmentation?

In binary image segmentation, for given a set of images, it's true mask and predicted mask. How do you compute dice score? Should I compute the dice score for each image separately and then find mean across all images? Or compute the dice score for all images at once by flattening tensor? Which is the correct way?
Category: Data Science

The channel dimension of the inputs should be defined. Found `None`

Hello I'm trying to use SegNet in my project with tensorflow, for educational purpose. And I'm surely following someone else's code on GitHub: conv_14 = Conv2D(512, (kernel, kernel), padding="same")(unpool_1) But it is giving me something like: The channel dimension of the inputs should be defined. Found `None`. How can resolve this? I checked, i've passed all the necessary params to it. Unpooling instance is created somewhat like this: pool_5, mask_5 = MaxPoolingWithArgmax2D(pool_size)(conv_13) print("Build enceder done..") # decoder unpool_1 = MaxUnpooling2D(pool_size)([pool_5, …
Category: Data Science

how to visualize segmented labels in a already existing graph?

I am working on a project where I have to segment the image using multi-class segmentation (3 classes) on microscopic images. Now let's say that I am segmenting solid, liquid and gas images (this is an example made up for asking the question because I am not allowed to discuss anything about the project :( ), I have pixel wise segmented solid, liquid and gas. But now, once I have segmented these images, I want to put the results on …
Category: Data Science

How to extract contents by topic from a document?

I am trying to extract information from resumes. I tried the pdfminer for the text extraction. But I need to extract the contents from a resume with respect to its title. For example: I will be giving my educational details under a title EDUCATIONAL BACKGROUND, so I have to extract the content topic wise. Is it possible to extract like that? What will be the process behind that? Is it possible to approach the problem in a segmentation manner.
Category: Data Science

What is Deep supervision?

I'm interested in segmentation models for medical imaging purposes. When I looked at the state of the art, I fell on a paper on a new architecture, Unet++: UNet++: A Nested U-Net Architecture for Medical Image Segmentation from Zongwei Zhou, Md Mahfuzur Rahman Siddiquee, Nima Tajbakhsh, and Jianming Liang at Arizona State University Like Unet, it is has an encoder/decoder architecture with skip connections (adding fine-grained feature maps of the encoder to the decoder). However, in Unet++, the skip connections …
Category: Data Science

Image segmentation with U-net

I am trying to understand if Semantic segmentation with U-NET. Are we training kernels to extract features or are we training a fully connected layer at the end? Or both? If so, how are we training them? how are we using the loss function to train them? Because based on this picture, i don't think there is a need for a fully connected layer at the end. If we just train our kernels, U-net will just do the image segmentation. …
Category: Data Science

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.