-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from RomainUSA/master
Universal Labeling Merging and Separating algorithm deployment
- Loading branch information
Showing
18 changed files
with
823 additions
and
114 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
FROM python:3.7 | ||
|
||
RUN apt-get update && apt-get install -y \ | ||
git \ | ||
libx11-6 \ | ||
libgl1 \ | ||
libopengl0 \ | ||
libegl1 \ | ||
wget | ||
|
||
|
||
RUN mkdir /app | ||
WORKDIR /app | ||
|
||
RUN wget https://github.com/RomainUSA/fly-by-cnn/releases/download/2.1.0/requirements.txt | ||
RUN pip3 install -r /app/requirements.txt | ||
|
||
RUN wget https://github.com/RomainUSA/fly-by-cnn/archive/refs/tags/2.1.0.zip | ||
RUN unzip 2.1.0.zip | ||
RUN rm -rf 2.1.0.zip | ||
|
||
|
||
RUN mkdir /app/models | ||
WORKDIR /app/models | ||
|
||
RUN wget https://github.com/RomainUSA/fly-by-cnn/releases/download/2.1.0/nnLU_model_5.hdf5 | ||
RUN wget https://github.com/RomainUSA/fly-by-cnn/releases/download/2.1.0/model_features.zip | ||
RUN unzip model_features.zip | ||
RUN rm -rf model_features.zip | ||
|
||
|
||
WORKDIR /app | ||
RUN wget https://github.com/RomainUSA/fly-by-cnn/releases/download/2.1.0/groundtruth.zip | ||
RUN unzip groundtruth.zip | ||
RUN rm -rf groundtruth.zip | ||
|
||
RUN mkdir /app/data | ||
RUN mkdir /app/data/input | ||
RUN mkdir /app/data/uid | ||
RUN mkdir /app/data/out_tmp | ||
RUN mkdir /app/data/merged | ||
RUN mkdir /app/data/out | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import os | ||
|
||
from keras.models import Sequential | ||
from keras.layers import LSTM, Dense, Input, Bidirectional | ||
from tensorflow.keras.optimizers import * | ||
|
||
|
||
def LSTM_model(): | ||
model = Sequential() | ||
|
||
# Two bidirectional LSTM layers | ||
model.add(Bidirectional(LSTM(64, return_sequences=True), input_shape=(64,512))) | ||
model.add(Bidirectional(LSTM(64))) | ||
|
||
# Sequence voting layer | ||
model.add(Dense(64)) | ||
|
||
# Fully connected layer | ||
model.add(Dense(1, activation='sigmoid')) | ||
|
||
# Compile the model | ||
model.compile(optimizer=Adam(lr = 1e-4), loss='binary_crossentropy', metrics=['accuracy']) | ||
model.summary() | ||
|
||
return model | ||
|
||
|
||
|
||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
from model import * | ||
from tensorflow.keras.models import load_model | ||
from sklearn.metrics import classification_report | ||
|
||
import argparse | ||
import os | ||
import itk | ||
|
||
import numpy as np | ||
import tensorflow as tf | ||
|
||
|
||
parser = argparse.ArgumentParser(description='Predict an input with a trained neural network', formatter_class=argparse.ArgumentDefaultsHelpFormatter) | ||
|
||
in_group = parser.add_mutually_exclusive_group(required=True) | ||
in_group.add_argument('--features', type=str, help='Input features to be predict as an Upper or Lower teeth') | ||
in_group.add_argument('--dir_features', type=str, help='Input dir features to be predict as an Upper or Lower teeth') | ||
|
||
parser.add_argument('--load_model', type=str, help='Saved model', required=True) | ||
parser.add_argument('--display', type=bool, help='display the prediction', default=False) | ||
|
||
args = parser.parse_args() | ||
|
||
inputFeatures = args.features | ||
inputdirFeatures = args.dir_features | ||
loadModelPath = args.load_model | ||
|
||
|
||
|
||
def ReadImage(fName, image_dimension=2, pixel_dimension=-1): | ||
if(image_dimension == 1): | ||
if(pixel_dimension != -1): | ||
ImageType = itk.Image[itk.Vector[itk.F, pixel_dimension], 2] | ||
else: | ||
ImageType = itk.VectorImage[itk.F, 2] | ||
else: | ||
if(pixel_dimension != -1): | ||
ImageType = itk.Image[itk.Vector[itk.F, pixel_dimension], image_dimension] | ||
else: | ||
ImageType = itk.VectorImage[itk.F, image_dimension] | ||
|
||
img_read = itk.ImageFileReader[ImageType].New(FileName=fName) | ||
img_read.Update() | ||
img = img_read.GetOutput() | ||
return img | ||
|
||
def process_scan(path): | ||
img = ReadImage(path) | ||
img_np = itk.GetArrayViewFromImage(img) | ||
img_np = np.reshape(img_np, [s for s in img_np.shape if s != 1]) | ||
return img_np | ||
|
||
|
||
|
||
if (args.dir_features): | ||
features_paths = [os.path.join(inputdirFeatures, x) for x in os.listdir(inputdirFeatures) if not x.startswith(".")] | ||
features_name = [y for y in os.listdir(inputdirFeatures) if not y.startswith(".")] | ||
features = np.array([process_scan(path) for path in features_paths]) | ||
|
||
if (args.features): | ||
features_name = inputFeatures.split("/")[-1] | ||
features = np.array([process_scan(inputFeatures)]) | ||
|
||
|
||
model = load_model(loadModelPath) | ||
predictions = model.predict(features) | ||
|
||
|
||
y_true = [] | ||
for i in range(len(features_name)): | ||
if features_name[i][:1]=="L": | ||
y_true.append(0) | ||
|
||
if features_name[i][:1]=="U": | ||
y_true.append(1) | ||
|
||
predictions[predictions>0.5]=1 | ||
predictions[predictions<=0.5]=0 | ||
|
||
|
||
|
||
if (args.display): | ||
target_names = ['Lower', 'Upper'] | ||
print(classification_report(y_true, predictions, target_names=target_names)) | ||
|
||
|
||
|
||
|
Oops, something went wrong.