File size: 1,736 Bytes
75ea7e6 d77453d ab657c0 84f0951 75ea7e6 ab657c0 75ea7e6 84f0951 ab657c0 84f0951 ab657c0 84f0951 ab657c0 84f0951 ab657c0 84f0951 4a24509 84f0951 4a24509 affa873 84f0951 ab657c0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
import gradio as gr
import subprocess
import os
import numpy as np
from PIL import Image
os.environ['data_raw'] = 'data_raw/'
os.environ['nnUNet_raw_data_base'] = 'nnUNet_raw_data_base/'
os.environ['nnUNet_preprocessed'] = 'nnUNet_preprocessed/'
os.environ['RESULTS_FOLDER'] = 'calvingfronts/'
model_path = 'Task500_Glacier_zonefronts'
def run_front_detection(input_img):
image_gray = input_img.convert("L")
image_gray.save('data_raw/test.png')
subprocess.run(
['python3', 'nnunet/dataset_conversion/Task500_Glacier_inference.py', '-data_percentage', '100', '-base',
os.environ['data_raw']])
cmd = [
'python3', 'nnunet/inference/predict_simple.py',
'-i', os.path.join(os.environ['nnUNet_raw_data_base'], 'nnUNet_raw_data/Task500_Glacier_zonefronts/imagesTs/'),
'-o', os.path.join(os.environ['RESULTS_FOLDER'], 'fold_0'),
'-t', '500','-m','2d','-f','0','-p', 'nnUNetPlansv2.1', '-tr','nnUNetTrainerV2', '-model_folder_name',
model_path
]
subprocess.run(cmd)
subprocess.run(['python3', 'nnunet/dataset_conversion/Task500_Glacier_reverse.py', '-i',
os.path.join(os.environ['RESULTS_FOLDER'], 'fold_0')])
os.remove('data_raw/test.png')
os.remove('nnUNet_raw_data_base/nnUNet_raw_data/Task500_Glacier_zonefronts/imagesTs/test_0000.nii.gz')
front = Image.open(os.path.join(os.environ['RESULTS_FOLDER'], 'tifs/test_front.png'))
os.remove(os.path.join(os.environ['RESULTS_FOLDER'],'fold_0/test.nii.gz'))
os.remove(os.path.join(os.environ['RESULTS_FOLDER'], 'tifs/test_front.png'))
return front
demo = gr.Interface(run_front_detection, gr.Image(type='pil'), "image",interface_size=(1000, 1000))
demo.launch() |