Seismic Facies Identification Challenge
[Explainer] Detectron2 & COCO Dataset 🔥 • Web Application & Visualizations • End-to-End Baseline & Tensorflow
Detectron2 & COCO Dataset 🔥 • Web Application & Visualizations • End-to-End Baseline & Tensorflow
So, me Shubhamai and I have come up with these 3 things -
COCO Dataset & using Detectron2, MMDetection
YES! I have converted this dataset into COCO Dataset and which we train Mask-RCNN using Detectron2.
There we go boys - Colab Link
More things will be added so like this post RIGHT NOW
Web Application & Visualisation
https://seismic-facies-identification.herokuapp.com/
But this time, I found that a great preprocessing pipeline can help to model to find accurate features and increasing overall accuracy. But it kinda isn’t that easy as it looks —
So I made a Web Application based on that which allows you to play/experiment with many of the image preprocessing functions/methods, changing parameters or writing custom image preprocessing functions to experiment.
And it also contains all the visualizations from the colab notebook .
I hope that it will help you in making the perfect preprocessing pipelines .
End-to-End Baseline & Tensorflow
https://colab.research.google.com/drive/1t1hF_Vs4xIyLGMw_B9l1G6qzLBxLB5eG?usp=sharing
I have made a complete colab notebook from Data Exploration to Submitting Predictions. Here are some of the glimpse of the image visualization section!
And this 3D Plot!
Tables of Content -
- Setting our Workspace
- Data Exploration
- Image Preprocessing Techniqes
- Creating our Dataset
- Creating our Model
- Training the Model
- Evaluating the model
- Testing on test Data
- Generate More Data + Some tips & tricks
The main libraries covered in this notebook is —
- Tensorflow 2.0 & Keras
- Plotly
- cv2
and much more…
The model that i am using is UNet, pretty much standard in image segmentation. More is in the colab notebook!
I hope the colab notebook will help you get started in this competition or learning something new . If the notebook did help you, make sure to like the post. lol.
https://colab.research.google.com/drive/1t1hF_Vs4xIyLGMw_B9l1G6qzLBxLB5eG?usp=sharing
Please like the topic if this helps in any way possible . I really appreciate that
🌎 Facies Identification Challenge: 3D image interpretation by Machine Learning¶
In this challange we need to identify facies as an image, from 3D seismic image using Deep Learing with various tools like tensorflow, keras, numpy, pandas, matplotlib, plotly and much much more..
Problem¶
Segmentating the 3D seismic image into an image with each pixel can be classfied into 6 labels based on patterns in the image.
https://www.aicrowd.com/challenges/seismic-facies-identification-challenge#introduction
Dataset¶
We have 3D datasets both ( features X, and labels Y ) with shape for X in 1006 × 782 × 590, in axis corresponding Z, X, Y and Y in 1006 × 782 × 590 in also axis corresponsing Z, X, Y.
https://www.aicrowd.com/challenges/seismic-facies-identification-challenge/dataset_files
We can say that we have total of 2,378 trainig images with their corresponsing labels and we also have same number of 2,378 testing images which we will predict labels for.
https://www.aicrowd.com/challenges/seismic-facies-identification-challenge#dataset
Evaluation¶
The evaluation metrics are the F1 score and accuracy.
https://www.aicrowd.com/challenges/seismic-facies-identification-challenge#evaluation-criteria
Tables of Content¶
- Setting our Workspace 💼
- Downloading our Dataset
- Importing Necessary Libraries
Data Exploration 🧐
- Reading our Dataset
- Image Visualisations
Image Preprocessing Techniqes 🧹
- Image preprocessing
Creating our Dataset 🔨
- Loading data into memory
- Making 2D Images
Creating our Model 🏭
- Creating Unet Model
- Setting up hyperparameters
Training the Model 🚂
- Setting up Tensorboard
- Start Training!
Evaluating the model 🧪
- Evaluating our Model
Testing on test Data 💯
Generate More Data + Some tips & tricks 💡
Setting our Workspace 💼¶
In this section we are going to download our dataset & also downloading some libraries, and then importing up all libraries to get ready!
Downloading our Dataset¶
# Downloading training data ( Seismic Images | X )
!wget https://datasets.aicrowd.com/default/aicrowd-public-datasets/seamai-facies-challenge/v0.1/public/data_train.npz
# Downloading training data ( Labels | Y )
!wget https://datasets.aicrowd.com/default/aicrowd-public-datasets/seamai-facies-challenge/v0.1/public/labels_train.npz
# Downloading Testing Dataset
!wget https://datasets.aicrowd.com/default/aicrowd-public-datasets/seamai-facies-challenge/v0.1/public/data_test_1.npz
Importing Necessary Libraries¶
!pip install git+https://github.com/tensorflow/examples.git
!pip install git+https://github.com/karolzak/keras-unet
# # install dependencies: (use cu101 because colab has CUDA 10.1)
!pip install -U torch==1.5 torchvision==0.6 -f https://download.pytorch.org/whl/cu101/torch_stable.html
!pip install cython pyyaml==5.1
!pip install -U 'git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI'
import torch, torchvision
print(torch.__version__, torch.cuda.is_available())
!gcc --version
# install detectron2:
!pip install detectron2==0.1.2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cu101/index.html
!pip install imantics
# For data preprocessing & manipulation
import numpy as np
import pandas as pd
# FOr data visualisations & graphs
import matplotlib.pyplot as plt
import plotly.graph_objects as go
import plotly.express as px
from plotly.subplots import make_subplots
# utilities
from tqdm.notebook import tqdm
import datetime
from IPython.display import HTML
import os
# For Deep learning
import tensorflow as tf
from tensorflow_examples.models.pix2pix import pix2pix
import tensorflow_datasets as tfds
import tensorflow_addons as tfa
# For Image Preprocessing
import cv2
# Detectron2
import detectron2
from detectron2.utils.logger import setup_logger
from imantics import Polygons, Mask
setup_logger()
import random
# import some common detectron2 utilities
from detectron2 import model_zoo
from detectron2.engine import DefaultPredictor
from detectron2.config import get_cfg
from detectron2.utils.visualizer import Visualizer
from detectron2.data import MetadataCatalog
from detectron2.structures import BoxMode
from pycocotools import mask
from skimage import measure
from detectron2.data import DatasetCatalog, MetadataCatalog
from detectron2.engine import DefaultTrainer
from detectron2.config import get_cfg
# Setting a bigger figure size
plt.rcParams["figure.figsize"] = (20, 15)
Data Exploration 🧐¶
In this section we are going to explore our dataset, firstly load it and seeing some array, categories and then image visualisations
Reading Our Dataset¶
# Reading our Training dataset ( Seismic Images | X )
data = np.load("/content/data_train.npz",
allow_pickle=True, mmap_mode = 'r')
# Reading our Traning Dataset ( Labels | Y)
labels = np.load("/content/labels_train.npz",
allow_pickle=True, mmap_mode = 'r')
# Picking the actual data
X = data['data']
Y = labels['labels']
# Dimensions of features & labels
X.shape, Y.shape
# Showing the data
X[:, 6, :], Y[:, 6, :]
Here we are making a 2D array of image, so we are picking the 6th index of X axis and seing the Z and Y axis values!
Also it looks like that we have got negative values also in X, but the Y looks good!
np.unique(Y)
Ther are 6 different unique values in labels, as said before, each pixel can be classified into 6 different labels
Image Visualisations¶
# Making a subplot with 1 row and 2 column
fig = make_subplots(1, 2, subplot_titles=("Image", "Label"))
# Visualising a section of the 3D array
fig.add_trace(go.Heatmap(z=X[:, :, 70][:300, :300]), 1, 1)
fig.add_trace(go.Heatmap(z=Y[:, :, 70][:300, :300]), 1, 2)
fig.update_layout(height=600, width=1100, title_text="Seismic Image & Label")
HTML(fig.to_html())
# Making a subplot with 1 row and 2 column
fig = make_subplots(1, 2, subplot_titles=("Image", "Label"), specs=[[{"type": "Surface"}, {"type": "Surface"}]])
# Making a 3D Surphace graph with image and corresponsing label
fig.add_trace(go.Surface(z=X[:,75, :][:300, :300]), 1, 1)
fig.add_trace(go.Surface(z=Y[:,75, :][:300, :300]), 1, 2)
fig.update_layout(height=600, width=1100, title_text="Seismic Image & Label in 3D!")
HTML(fig.to_html())
# Making a subplot with 1 row and 2 column
fig = make_subplots(1, 2, subplot_titles=("Image", "Label"))
# Making a contour graph
fig.add_trace(go.Contour(
z=X[:,34, :][:300, :300]), 1, 1)
fig.add_trace(go.Contour(
z=Y[:,34, :][:300, :300]
), 1, 2)
fig.update_layout(height=600, width=1100, title_text="Seismic Image & Label in with contours")
HTML(fig.to_html())
# Making a subplot with 2 row and 2 column
fig = make_subplots(2, 2, subplot_titles=("Image", "Label", "Label Histogram"))
# Making a contour graph
fig.add_trace(go.Contour(
z=X[:,34, :][:300, :300], contours_coloring='lines',
line_width=2,), 1, 1)
# Showing the label ( also the contour )
fig.add_trace(go.Contour(
z=Y[:,34, :][:300, :300]
), 1, 2)
# Showing histogram for the label column
fig.add_trace(go.Histogram(x=Y[:,34, :][:300, :300].ravel()), 2, 1)
fig.update_layout(height=800, width=1100, title_text="Seismic Image & Label in with contours ( only line )")
HTML(fig.to_html())
# Making a subplot with 2 row and 1 column
fig = make_subplots(2, 1, subplot_titles=("Image", "label"))
# Making a contour graph
fig.add_trace(
go.Contour(
z=X[:,:, 56][:200, :200]
), 1, 1)
fig.add_trace(go.Contour(
z=Y[:,:, 56][:200, :200]
), 2, 1)
fig.update_layout(height=1000, width=1100, title_text="Seismic Image & Label in with contours ( More Closer Look )")
HTML(fig.to_html())
Image Preprocessing Techniqes 🧹¶
In this section we are going to take a look at some image processing technique to see how we can improve the features so that our model and give more accuracy!
# Reading a sample seismic image with label
img = X[:,:, 56]
label = Y[:, :, 56]
plt.imshow(img, cmap='gray')
plt.show()
plt.imshow(label)
# Image Thresholding
ret,thresh1 = cv2.threshold(img,0,255,cv2.THRESH_TOZERO)
plt.imshow(thresh1, cmap='gray')