-
Notifications
You must be signed in to change notification settings - Fork 1
/
stainsegmentation.py
53 lines (43 loc) · 1.67 KB
/
stainsegmentation.py
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
43
44
45
46
47
48
49
50
51
52
53
# This script is to replace "segmentation.sh"
import os
import configparser
from pathlib import Path
# Get the directory of the current script
script_dir = Path(__file__).parent.absolute()
# Set the path to config.ini based on the script directory
config_ini_path = script_dir / "config.ini"
print(config_ini_path)
# Read parameters from config.ini using Python
config = configparser.ConfigParser()
config.read(config_ini_path)
raw_directory = config["Settings"]["image_path"]
mask_directory = config["StainSegmentation"]["mask_directory"]
config_param = config["StainSegmentation"]["config"]
model = config["StainSegmentation"]["model"]
print(f"RAW_DIR={raw_directory}")
print(f"MASK_DIR={mask_directory}")
print(f"CONFIG={config_param}")
print(f"MODEL={model}")
# Ensure the mask_directory exists
# os.makedirs(mask_directory, exist_ok=True)
# print(f"Ensured existence of directory: {mask_directory}")
# Ensure the output directory exists
if not os.path.exists(mask_directory):
os.makedirs(mask_directory)
# Get the model path
model_path = config["StainSegmentation"]["model"]
print(f"MODEL_PATH={model_path}")
# Define the directory where inference.py is located
pytorch_segmentation_dir = "/home/roboticslab/Developer/pytorch_concrete_flaws_segmentation"
# Combined command to activate conda environment and run the Python script
# source '/home/roboticslab/miniconda3/etc/profile.d/conda.sh' && \
# conda activate visualinspection113 && \
command = f"""
cd "{pytorch_segmentation_dir}" && python3 inference.py \
--config "{config_param}" \
--model "{model_path}" \
--images "{raw_directory}" \
--output "{mask_directory}" \
--extension jpg png JPG
"""
os.system(command)