This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import import_ipynb | |
from utils import mask2rle,combined_loss,dice_coef | |
import cv2 | |
import tensorflow as tf | |
from tensorflow import keras | |
from tqdm import tqdm | |
def predict_results(test_files_png): | |
''' | |
Given a list of chest Xray image files it generates prediction results for Pneumothorax disease | |
Args: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%env SM_FRAMEWORK=tf.keras | |
import segmentation_models as sm | |
import tensorflow as tf | |
from tensorflow import keras | |
def get_segmentaion_model(name= 'Uefficientnetb4', BACKBONE = 'efficientnetb4',ENCODER_WEIGHTS = 'imagenet'): | |
''' | |
Creates segmentaion model object and compiles it with Adam optimizer and combined_loss function | |
Args: | |
name : Name of model | |
BACKBONE : BACKBONE model name to be used as encider part |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
from tensorflow.keras import Model | |
dense_net_121 = tf.keras.applications.DenseNet121(input_shape=[256,256,3],include_top=False,pooling='avg') | |
base_model_output = tf.keras.layers.Dense(units=14,activation='relu')(dense_net_121.output) | |
base_model = Model(inputs = dense_net_121.input,outputs=base_model_output) | |
base_model.load_weights('brucechou1983_CheXNet_Keras_0.3.0_weights.h5') | |
output_layer = tf.keras.layers.Dense(1,activation='sigmoid')(base_model.layers[-2].output) | |
model = Model(inputs=base_model.inputs, outputs=output_layer) | |
model1=tf.keras.layers.UpSampling2D((2,2))(model.layers[-3].output) | |
model1=tf.keras.layers.concatenate([model1,model.get_layer('pool4_conv').output]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
from tensorflow import keras | |
def get_CheXNet_model(HEIGHT,WIDTH,N_CHANNELS): | |
base_model = keras.applications.DenseNet121( | |
weights=None, | |
include_top=False, | |
input_shape=(HEIGHT,WIDTH,N_CHANNELS), pooling="avg" | |
) | |
predictions = keras.layers.Dense(14, activation='sigmoid', name='predictions')(base_model.output) | |
base_model = keras.Model(inputs=base_model.input, outputs=predictions,name='CheXNet') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def conv_block(input, num_filters): | |
x = Conv2D(num_filters, 3, padding="same")(input) | |
x = BatchNormalization()(x) | |
x = Activation("relu")(x) | |
x = Conv2D(num_filters, 3, padding="same")(x) | |
x = BatchNormalization()(x) | |
x = Activation("relu")(x) | |
return x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def extract_metadata_from_images(file_path): | |
''' | |
Extracts metadata present in DICOM file | |
Args: | |
file : DICOM file path | |
Returns: | |
a dictionary containing important metadata | |
''' | |
dataset = pydicom.dcmread(file_path) |