generated from dopt-python/py311
change folder name to match package name
This commit is contained in:
parent
1d5ab6ad00
commit
9d72004c9a
10
src/dopt_sensor_anomalies/constants.py
Normal file
10
src/dopt_sensor_anomalies/constants.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
from typing import Final
|
||||||
|
|
||||||
|
THRESHOLD_BW: Final[int] = 63 # threshold to distringuish black (electrodes) and white areas
|
||||||
|
# model_path = [
|
||||||
|
# r"C:\Users\demon\Documents\EKF\Modelle\patchcore_model_links.pth",
|
||||||
|
# r"C:\Users\demon\Documents\EKF\Modelle\patchcore_model_rechts.pth",
|
||||||
|
# ] # path to anomaly detection models
|
||||||
|
BACKBONE: Final[str] = "resnet18" # parameters for AI model
|
||||||
|
LAYERS: Final[tuple[str, str]] = ("layer1", "layer2")
|
||||||
|
RATIO: Final[float] = 0.05
|
||||||
@ -19,21 +19,20 @@ from scipy.spatial import distance as dist
|
|||||||
from torch import as_tensor, cuda, device, float32, load, no_grad
|
from torch import as_tensor, cuda, device, float32, load, no_grad
|
||||||
from torchvision.transforms.v2.functional import to_dtype, to_image
|
from torchvision.transforms.v2.functional import to_dtype, to_image
|
||||||
|
|
||||||
# input parameters
|
from dopt_sensor_anomalies import constants as const
|
||||||
|
|
||||||
|
# input parameters: user-defined
|
||||||
file_path = r"C:\Users\demon\Documents\EKF\Analyse_fuer_Florian\bild2.bmp"
|
file_path = r"C:\Users\demon\Documents\EKF\Analyse_fuer_Florian\bild2.bmp"
|
||||||
pixelsPerMetricX = 0.251
|
pixelsPerMetricX = 0.251
|
||||||
pixelsPerMetricY = 0.251
|
pixelsPerMetricY = 0.251
|
||||||
|
|
||||||
|
|
||||||
# internal parameters
|
# internal parameters - configuration
|
||||||
schwellwert = 63 # threshold to distringuish black (electrodes) and white areas
|
schwellwert = 63 # threshold to distinguish black (electrodes) and white areas
|
||||||
model_path = [
|
model_path = [
|
||||||
r"C:\Users\demon\Documents\EKF\Modelle\patchcore_model_links.pth",
|
r"C:\Users\demon\Documents\EKF\Modelle\patchcore_model_links.pth",
|
||||||
r"C:\Users\demon\Documents\EKF\Modelle\patchcore_model_rechts.pth",
|
r"C:\Users\demon\Documents\EKF\Modelle\patchcore_model_rechts.pth",
|
||||||
] # path to anomaly detection models
|
] # path to anomaly detection models
|
||||||
backbone = "resnet18" # parameters for AI model
|
|
||||||
layers = ["layer1", "layer2"]
|
|
||||||
ratio = 0.05
|
|
||||||
|
|
||||||
|
|
||||||
# measuring
|
# measuring
|
||||||
@ -114,7 +113,7 @@ def measure_length(file_path, pixelsPerMetricX, pixelsPerMetricY):
|
|||||||
|
|
||||||
# change colours in the image to black and white
|
# change colours in the image to black and white
|
||||||
gray = cv2.cvtColor(cropped, cv2.COLOR_BGR2GRAY)
|
gray = cv2.cvtColor(cropped, cv2.COLOR_BGR2GRAY)
|
||||||
_, binary = cv2.threshold(gray, schwellwert, 255, cv2.THRESH_BINARY)
|
_, binary = cv2.threshold(gray, const.THRESHOLD_BW, 255, cv2.THRESH_BINARY)
|
||||||
|
|
||||||
# perform edge detection, identify rectangular shapes
|
# perform edge detection, identify rectangular shapes
|
||||||
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (5, 5))
|
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (5, 5))
|
||||||
@ -350,7 +349,9 @@ def anomaly_detection(file_path, data_csv, sensor_images):
|
|||||||
folder_path = path.dirname(file_path)
|
folder_path = path.dirname(file_path)
|
||||||
|
|
||||||
# reconstruct the model and initialize the engine
|
# reconstruct the model and initialize the engine
|
||||||
model = Patchcore(backbone=backbone, layers=layers, coreset_sampling_ratio=ratio)
|
model = Patchcore(
|
||||||
|
backbone=const.BACKBONE, layers=const.LAYERS, coreset_sampling_ratio=const.RATIO
|
||||||
|
)
|
||||||
engine = Engine()
|
engine = Engine()
|
||||||
|
|
||||||
# preparation for plot
|
# preparation for plot
|
||||||
Loading…
x
Reference in New Issue
Block a user