From 7a9c02d4dd2741371a1efa078e3d845aa7a295c1 Mon Sep 17 00:00:00 2001
From: neo-dl
Date: Fri, 22 Jul 2022 18:16:52 +0200
Subject: [PATCH 1/5] performancer on inference
---
src/components/vision.py | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/components/vision.py b/src/components/vision.py
index 33a7413..427e650 100644
--- a/src/components/vision.py
+++ b/src/components/vision.py
@@ -10,6 +10,8 @@ import cv2
import numpy as np
from PyQt5.QtWidgets import QApplication
+from lib.helpers import time_this
+
if "--no-gpu" in sys.argv:
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
@@ -37,8 +39,8 @@ else:
if "--no-tflite" not in sys.argv:
try:
- Interpreter = tf.lite.Interpreter
- # from tflite_runtime.interpreter import Interpreter
+ #Interpreter = tf.lite.Interpreter
+ from tflite_runtime.interpreter import Interpreter
except (ImportError, ModuleNotFoundError):
logging.exception(traceback.format_exc())
@@ -335,6 +337,7 @@ class Vision(Component):
self.log.info(f"initialized model {self.model!r} with mode {self.tf_mode!r}")
self.loading_model_signal.emit({"status": "done"})
+ @time_this
def check_features(self, frame, lock=True):
if self.interpreter is not None and frame.shape != self.interpreter.get_input_details()[0]["shape"][1:3]:
tensor = np.expand_dims(cv2.resize(frame, self.interpreter.get_input_details()[0]["shape"][1:3], interpolation=cv2.INTER_LINEAR), axis=0)
@@ -693,10 +696,7 @@ class Vision(Component):
# VISION_CONSUMER TASK
if consumable is None:
return
- t1=time.time()
detections = self.check_features(consumable["frame"])
- t2=time.time()
- print(f"detection time: {(t2-t1):.3f}")
results = self.process_detections(detections)
return {"detections": detections, "results": results}
From 3c2d6f37752f9b25e33c842605dcda8d7762325a Mon Sep 17 00:00:00 2001
From: stres1
Date: Thu, 28 Jul 2022 12:27:54 +0200
Subject: [PATCH 2/5] dev
---
config/machine_settings/defaults.ini | 2 +-
config/machine_settings/hostnames.ini | 1 +
config/machine_settings/stres1.ini | 8 +
config/vision/labels/labels.pbtxt | 2 +-
designer_win.sh | 2 +
run_chart_example.sh | 4 -
run_lifecycle.sh | 4 -
src/components/neo_pixels.py | 21 +-
src/components/tecna_marposs_provaset_t3p.py | 2 +-
.../tecna_marposs_provaset_t3p_registers.py | 18 +-
src/components/vision.py | 6 +-
src/test/multicomp.py | 5 +-
src/test/neo_lights.py | 4 +-
src/ui/test/test.py | 12 +-
src/ui/test_leak/test_leak.ui | 977 +++++++++---------
15 files changed, 533 insertions(+), 535 deletions(-)
create mode 100644 config/machine_settings/stres1.ini
create mode 100644 designer_win.sh
delete mode 100755 run_chart_example.sh
delete mode 100755 run_lifecycle.sh
diff --git a/config/machine_settings/defaults.ini b/config/machine_settings/defaults.ini
index 3ac4deb..912cb44 100644
--- a/config/machine_settings/defaults.ini
+++ b/config/machine_settings/defaults.ini
@@ -43,7 +43,7 @@ port: COM1
baudrate: 9600
[vision]
-detection_threshold: 0.5
+detection_threshold: 0.75
neural_network: hs3-20000
; recipes_path: ./config/vision_test_recipes
diff --git a/config/machine_settings/hostnames.ini b/config/machine_settings/hostnames.ini
index ec8cff8..50cc150 100644
--- a/config/machine_settings/hostnames.ini
+++ b/config/machine_settings/hostnames.ini
@@ -2,3 +2,4 @@
this: this
mino: mino
DESKTOP-VOCOB38: vm
+ST-RES-1: stres1
\ No newline at end of file
diff --git a/config/machine_settings/stres1.ini b/config/machine_settings/stres1.ini
new file mode 100644
index 0000000..b338022
--- /dev/null
+++ b/config/machine_settings/stres1.ini
@@ -0,0 +1,8 @@
+[tecna_t3]
+port: COM5
+
+[neo_pixels]
+port: COM4
+baudrate: 9600
+
+
diff --git a/config/vision/labels/labels.pbtxt b/config/vision/labels/labels.pbtxt
index 5cc99f0..4ab5798 100644
--- a/config/vision/labels/labels.pbtxt
+++ b/config/vision/labels/labels.pbtxt
@@ -1,7 +1,7 @@
item {
id: 1
name: 'hs-ok'
- color: '0x000000'
+ color: '0x55AA55'
}
item {
id: 2
diff --git a/designer_win.sh b/designer_win.sh
new file mode 100644
index 0000000..11fefa5
--- /dev/null
+++ b/designer_win.sh
@@ -0,0 +1,2 @@
+#!/bin/bash
+venv/Lib/site-packages/qt5_applications/Qt/bin/designer
diff --git a/run_chart_example.sh b/run_chart_example.sh
deleted file mode 100755
index 6b7f73c..0000000
--- a/run_chart_example.sh
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/bin/bash -e
-cd "$(dirname "$0")"
-source "./venv/Scripts/activate" || source "./venv/bin/activate"
-python -O "./src/lib/charts/MultiAxisExample.py"
diff --git a/run_lifecycle.sh b/run_lifecycle.sh
deleted file mode 100755
index 49e80f6..0000000
--- a/run_lifecycle.sh
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/bin/bash -e
-cd "$(dirname "$0")"
-source "./venv/Scripts/activate" || source "./venv/bin/activate"
-python -O "./src/lifecycle.py"
diff --git a/src/components/neo_pixels.py b/src/components/neo_pixels.py
index 7481d8a..6fb296d 100644
--- a/src/components/neo_pixels.py
+++ b/src/components/neo_pixels.py
@@ -1,4 +1,5 @@
import sys
+import time
import traceback
if "--sim-serial" in sys.argv:
@@ -16,6 +17,13 @@ C_UINT32_MAX = c_uint32(-1).value
class NeoPixels(Component):
def __init__(self, config=None, name=None):
super().__init__(config=config, name=name, threaded=False)
+ self.conn = serial.Serial(
+ self.port,
+ baudrate=self.baudrate,
+ stopbits=self.stopbits,
+ parity=self.parity,
+ bytesize=self.bytesize,
+ )
def config_changed(self):
self.port = self.config[self.name]["port"]
@@ -30,18 +38,11 @@ class NeoPixels(Component):
if not color.startswith("#") or len(color) != 7:
raise ValueError("the color parameter must be in the html hex format: '#RRGGBB'")
try:
- conn = serial.Serial(
- self.port,
- baudrate=self.baudrate,
- stopbits=self.stopbits,
- parity=self.parity,
- bytesize=self.bytesize,
- )
- conn.write(int.to_bytes(pixel, length=4, byteorder="big") + bytes.fromhex(color[1:7]) + b"\n")
- response = conn.readline()
+ self.conn.write(int.to_bytes(pixel, length=4, byteorder="big") + bytes.fromhex(color[1:7]) + b"\n")
+ response = self.conn.readline()
if response != "ok\n":
self.log.error(response.strip())
- conn.close()
+ # conn.close()
except serial.serialutil.SerialException:
self.log.exception(traceback.format_exc())
diff --git a/src/components/tecna_marposs_provaset_t3p.py b/src/components/tecna_marposs_provaset_t3p.py
index 3daee7b..6db4684 100644
--- a/src/components/tecna_marposs_provaset_t3p.py
+++ b/src/components/tecna_marposs_provaset_t3p.py
@@ -180,7 +180,7 @@ class TecnaMarpossProvasetT3P(ModbusComponent):
"Running test: test type",
"Running test: sequence index",
]}
- if info["Running test: active phase"] == "END TEST, WAITING THE START OF A NEW TEST":
+ if info["Running test: active phase"] == "FINE TEST":
info.update(self.get_test_results())
self.log.debug(str(info))
super()._get([info])
diff --git a/src/components/tecna_marposs_provaset_t3p_registers.py b/src/components/tecna_marposs_provaset_t3p_registers.py
index 071c46a..cdfeedf 100644
--- a/src/components/tecna_marposs_provaset_t3p_registers.py
+++ b/src/components/tecna_marposs_provaset_t3p_registers.py
@@ -7,7 +7,7 @@ registers = {
"Life counter: TOTAL TESTS": [8 - 1, {"dt": "32bit_uint", }],
"Real time test pressure output": [11 - 1, {"dt": "32bit_int", "f": 21, }],
"Real time differential pressure output": [13 - 1, {"dt": "32bit_int", "f": 22, }],
- "Real time pressure line regulator": [15 - 1, {"dt": "16bit_int", "f": 23, }],
+ "Real time pressure line regulator": [15 - 1, {"dt": "16bit_int", "f": 23,"g":0.1 }],
"Active alarm flags": [16 - 1, {"dt": "16bit_uint", }],
# | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
# | | | | A5 | A4 | A3 | A2 | A1 | | | | | | E3 | E2 | E1 |
@@ -28,9 +28,9 @@ registers = {
"Running test: flow rate format": [27 - 1, {"dt": "16bit_uint", }], # white
"Active test program number": [31 - 1, {"dt": "16bit_uint", }],
"Running test: active phase": [32 - 1, {"dt": "16bit_uint", "decoding": {
- 0: "WAITING START",
- 10: "CHECK BARCODE",
- 20: "WAITING BARCODE",
+ 0: "ATTESA START",
+ 10: "CONTROLLO BARCODE",
+ 20: "ATTESA BARCODE",
30: "START TEST",
40: "START CAGE",
50: "START PLUG",
@@ -38,10 +38,10 @@ registers = {
70: "WAIT DELAY ACKNOWLEDGE COMMAND",
80: "WAIT DELAY",
90: "WAIT ACKNOWLEDGE",
- 100: "T0 PRE-FILL",
- 110: "T1 FILLING",
- 120: "T2 SETTLING",
- 130: "T3 MEASURE",
+ 100: "T0 PRE-RIEMPIMENTO",
+ 110: "T1 RIEMPIMENTO",
+ 120: "T2 ASSESTAMENTO",
+ 130: "T3 MISURA",
140: "WAITING OPERATOR RESULT ACKNOWLEDGE",
150: "RESULT PRESENT",
160: "MARKING",
@@ -49,7 +49,7 @@ registers = {
180: "END SEQUENCE PROGRAM",
190: "END PLUG",
200: "END CAGE",
- 210: "END TEST, WAITING THE START OF A NEW TEST",
+ 210: "FINE TEST",
}, }],
"Running test: phase backwards time": [33 - 1, {"dt": "16bit_uint", "f": 26, }],
"Running test: filling pressure": [34 - 1, {"dt": "32bit_int", "f": 21, }],
diff --git a/src/components/vision.py b/src/components/vision.py
index bce2d84..a189c83 100644
--- a/src/components/vision.py
+++ b/src/components/vision.py
@@ -381,9 +381,9 @@ class Vision(Component):
if lock:
self.lock.unlock()
detections = {
- "detection_scores": [scores],
- "detection_boxes": [boxes],
- "detection_classes": [map(lambda class_id: class_id + 1, class_ids)],
+ "detection_scores": [scores][0:1],
+ "detection_boxes": [boxes][0:1],
+ "detection_classes": [map(lambda class_id: class_id + 1, class_ids)][0:1],
}
else:
detections = self.model(tensor)
diff --git a/src/test/multicomp.py b/src/test/multicomp.py
index c06d821..f23cacd 100644
--- a/src/test/multicomp.py
+++ b/src/test/multicomp.py
@@ -2,8 +2,11 @@ import time
import serial
+#tester_port="/dev/ttyUSB0"
+tester_port="COM1"
+
conn = serial.Serial(
- "/dev/ttyUSB0",
+ tester_port,
baudrate=115200,
stopbits=serial.STOPBITS_ONE,
parity=serial.PARITY_NONE,
diff --git a/src/test/neo_lights.py b/src/test/neo_lights.py
index c9a3394..2d29090 100644
--- a/src/test/neo_lights.py
+++ b/src/test/neo_lights.py
@@ -4,11 +4,13 @@ import serial
C_UINT32_MAX = c_uint32(-1).value
conn = serial.Serial(
- "/dev/ttyACM1",
+ "COM4",
baudrate=9600,
stopbits=serial.STOPBITS_ONE,
parity=serial.PARITY_NONE,
bytesize=serial.EIGHTBITS,
+ rtscts=False,
+ xonxoff=False
)
pixel = C_UINT32_MAX
color = "#ff00ff"
diff --git a/src/ui/test/test.py b/src/ui/test/test.py
index c5533ea..a3ada99 100755
--- a/src/ui/test/test.py
+++ b/src/ui/test/test.py
@@ -44,7 +44,7 @@ class Test(Widget):
"done": Test_Assembly(self.select_step_img("success"), u"COLLAUDO COMPLETATO"),
"emergency": Test_Assembly(self.select_step_img("reset_emergency"), u"EMERGENZA INTERVENUTA - RIPRISTINARE PULSANTE E SELEZIONARE \"RESET EMERGENZA\" DAL MEN\u00d9 \"STRUMENTI\""),
"fail": Test_Assembly(self.select_step_img("fail"), u"CICLO INTERROTTO"),
- "leak": Test_Assembly(None, u"PREMERE START PER COMINCIARE LA PROVA TENUTA E ATTENDERE IL SUO COMPLETAMENTO", Test_Leak(components=self.components, recipe=self.recipe, step=self.step)),
+ "leak": Test_Assembly(None, u"PREMERE START PER INIZIARE LA PROVA TENUTA", Test_Leak(components=self.components, recipe=self.recipe, step=self.step)),
"print": Test_Assembly(self.select_step_img("print"), u"STAMPA ETICHETTA IN CORSO"),
"select_recipe": Test_Assembly(None, u"SELEZIONARE IL CODICE DA COLLAUDARE", Recipe_Selection()),
"vision": Test_Assembly(None, u"VERIFICARE CONTROLLO CON TELECAMERA", Test_Vision(components=self.components, recipe=self.recipe, step=self.step)),
@@ -279,11 +279,13 @@ class Test(Widget):
def print(self, archived=None):
self.log.info("cycle print")
# LABEL PRINT
+ datamatrix= archived.recipe.part_number+ archived.time.strftime("%m%y")+f"{archived.id:0>5}"
+ dt_label=archived.time.strftime("%d/%m/%Y %H:%M:%S")
context = {
- "DATAMATRIX": str(self.data.get("barcodes", {}).get("serial", "")),
- "DATAMATRIX_TEXT": str(self.data.get("barcodes", {}).get("serial", "-")),
- "PIECE_NUM": str(self.data.get("barcodes", {}).get("serial", "-")),
- "DATETIME": str(archived.time.isoformat()),
+ "DATAMATRIX": datamatrix,
+ "DATAMATRIX_TEXT": datamatrix,
+ "PIECE_NUM": str(archived.id),
+ "DATETIME": dt_label,
"SHIFT": str(get_shift(archived.time)),
"STATION": str(self.machine_id),
"OPERATOR": str(Users.get_session().user.username),
diff --git a/src/ui/test_leak/test_leak.ui b/src/ui/test_leak/test_leak.ui
index 2ed8e36..0c4e305 100644
--- a/src/ui/test_leak/test_leak.ui
+++ b/src/ui/test_leak/test_leak.ui
@@ -6,505 +6,14 @@
0
0
- 305
- 459
+ 854
+ 704
Test Leak
- -
-
-
-
- 0
- 0
-
-
-
-
- 0
- 100
-
-
-
-
-
-
-
-
- 0
- 0
- 0
-
-
-
-
-
-
- 255
- 112
- 114
-
-
-
-
-
-
- 255
- 127
- 127
-
-
-
-
-
-
- 255
- 63
- 63
-
-
-
-
-
-
- 127
- 0
- 0
-
-
-
-
-
-
- 170
- 0
- 0
-
-
-
-
-
-
- 0
- 0
- 0
-
-
-
-
-
-
- 255
- 255
- 255
-
-
-
-
-
-
- 0
- 0
- 0
-
-
-
-
-
-
- 255
- 112
- 114
-
-
-
-
-
-
- 255
- 112
- 114
-
-
-
-
-
-
- 0
- 0
- 0
-
-
-
-
-
-
- 255
- 127
- 127
-
-
-
-
-
-
- 255
- 255
- 220
-
-
-
-
-
-
- 0
- 0
- 0
-
-
-
-
-
-
- 0
- 0
- 0
-
-
-
-
-
-
-
-
- 0
- 0
- 0
-
-
-
-
-
-
- 255
- 112
- 114
-
-
-
-
-
-
- 255
- 127
- 127
-
-
-
-
-
-
- 255
- 63
- 63
-
-
-
-
-
-
- 127
- 0
- 0
-
-
-
-
-
-
- 170
- 0
- 0
-
-
-
-
-
-
- 0
- 0
- 0
-
-
-
-
-
-
- 255
- 255
- 255
-
-
-
-
-
-
- 0
- 0
- 0
-
-
-
-
-
-
- 255
- 112
- 114
-
-
-
-
-
-
- 255
- 112
- 114
-
-
-
-
-
-
- 0
- 0
- 0
-
-
-
-
-
-
- 255
- 127
- 127
-
-
-
-
-
-
- 255
- 255
- 220
-
-
-
-
-
-
- 0
- 0
- 0
-
-
-
-
-
-
- 0
- 0
- 0
-
-
-
-
-
-
-
-
- 127
- 0
- 0
-
-
-
-
-
-
- 255
- 112
- 114
-
-
-
-
-
-
- 255
- 127
- 127
-
-
-
-
-
-
- 255
- 63
- 63
-
-
-
-
-
-
- 127
- 0
- 0
-
-
-
-
-
-
- 170
- 0
- 0
-
-
-
-
-
-
- 127
- 0
- 0
-
-
-
-
-
-
- 255
- 255
- 255
-
-
-
-
-
-
- 127
- 0
- 0
-
-
-
-
-
-
- 255
- 112
- 114
-
-
-
-
-
-
- 255
- 112
- 114
-
-
-
-
-
-
- 0
- 0
- 0
-
-
-
-
-
-
- 255
- 0
- 0
-
-
-
-
-
-
- 255
- 255
- 220
-
-
-
-
-
-
- 0
- 0
- 0
-
-
-
-
-
-
- 0
- 0
- 0
-
-
-
-
-
-
-
-
- 20
- 75
- true
-
-
-
- background-color:rgb(255, 112, 114);
-
-
- STOP
-
-
-
- -
-
-
-
- 0
- 0
-
-
-
-
- 12
- 75
- true
-
-
-
- FORZA ACCETTAZIONE
-
-
-
-
@@ -556,7 +65,7 @@
- 24
+ 12
75
true
@@ -679,7 +188,7 @@
- 24
+ 12
75
true
@@ -1231,6 +740,477 @@
+ -
+
+
+
+ 0
+ 0
+
+
+
+
+ 0
+ 100
+
+
+
+
+
+
+
+
+ 0
+ 0
+ 0
+
+
+
+
+
+
+ 255
+ 112
+ 114
+
+
+
+
+
+
+ 255
+ 127
+ 127
+
+
+
+
+
+
+ 255
+ 63
+ 63
+
+
+
+
+
+
+ 127
+ 0
+ 0
+
+
+
+
+
+
+ 170
+ 0
+ 0
+
+
+
+
+
+
+ 0
+ 0
+ 0
+
+
+
+
+
+
+ 255
+ 255
+ 255
+
+
+
+
+
+
+ 0
+ 0
+ 0
+
+
+
+
+
+
+ 255
+ 112
+ 114
+
+
+
+
+
+
+ 255
+ 112
+ 114
+
+
+
+
+
+
+ 0
+ 0
+ 0
+
+
+
+
+
+
+ 255
+ 127
+ 127
+
+
+
+
+
+
+ 255
+ 255
+ 220
+
+
+
+
+
+
+ 0
+ 0
+ 0
+
+
+
+
+
+
+ 0
+ 0
+ 0
+
+
+
+
+
+
+
+
+ 0
+ 0
+ 0
+
+
+
+
+
+
+ 255
+ 112
+ 114
+
+
+
+
+
+
+ 255
+ 127
+ 127
+
+
+
+
+
+
+ 255
+ 63
+ 63
+
+
+
+
+
+
+ 127
+ 0
+ 0
+
+
+
+
+
+
+ 170
+ 0
+ 0
+
+
+
+
+
+
+ 0
+ 0
+ 0
+
+
+
+
+
+
+ 255
+ 255
+ 255
+
+
+
+
+
+
+ 0
+ 0
+ 0
+
+
+
+
+
+
+ 255
+ 112
+ 114
+
+
+
+
+
+
+ 255
+ 112
+ 114
+
+
+
+
+
+
+ 0
+ 0
+ 0
+
+
+
+
+
+
+ 255
+ 127
+ 127
+
+
+
+
+
+
+ 255
+ 255
+ 220
+
+
+
+
+
+
+ 0
+ 0
+ 0
+
+
+
+
+
+
+ 0
+ 0
+ 0
+
+
+
+
+
+
+
+
+ 127
+ 0
+ 0
+
+
+
+
+
+
+ 255
+ 112
+ 114
+
+
+
+
+
+
+ 255
+ 127
+ 127
+
+
+
+
+
+
+ 255
+ 63
+ 63
+
+
+
+
+
+
+ 127
+ 0
+ 0
+
+
+
+
+
+
+ 170
+ 0
+ 0
+
+
+
+
+
+
+ 127
+ 0
+ 0
+
+
+
+
+
+
+ 255
+ 255
+ 255
+
+
+
+
+
+
+ 127
+ 0
+ 0
+
+
+
+
+
+
+ 255
+ 112
+ 114
+
+
+
+
+
+
+ 255
+ 112
+ 114
+
+
+
+
+
+
+ 0
+ 0
+ 0
+
+
+
+
+
+
+ 255
+ 0
+ 0
+
+
+
+
+
+
+ 255
+ 255
+ 220
+
+
+
+
+
+
+ 0
+ 0
+ 0
+
+
+
+
+
+
+ 0
+ 0
+ 0
+
+
+
+
+
+
+
+
+ 20
+ 75
+ true
+
+
+
+ background-color:rgb(255, 112, 114);
+
+
+ STOP
+
+
+
-
@@ -1239,6 +1219,13 @@
0
+
+
+ 12
+ 75
+ true
+
+
FORZA ACCETTAZIONE
From a0d1703e8f8ef56e7c15e9aec65c58e1a2564260 Mon Sep 17 00:00:00 2001
From: stres1
Date: Thu, 28 Jul 2022 16:13:09 +0200
Subject: [PATCH 3/5] detection no-tflite ok
---
src/components/vision.py | 6 +++++-
src/ui/test/test.py | 2 ++
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/components/vision.py b/src/components/vision.py
index a189c83..e78f8e1 100644
--- a/src/components/vision.py
+++ b/src/components/vision.py
@@ -315,6 +315,7 @@ class Vision(Component):
try:
# create tensorflow model
model = tf.saved_model.load(str(self.models_dir / model_name))
+ model = model.signatures['serving_default']
tf_mode = "normal"
except Exception:
self.log.exception(traceback.format_exc())
@@ -386,7 +387,10 @@ class Vision(Component):
"detection_classes": [map(lambda class_id: class_id + 1, class_ids)][0:1],
}
else:
- detections = self.model(tensor)
+ input_tensor = tf.convert_to_tensor(np.asarray(tensor))
+ #input_tensor = input_tensor[tf.newaxis, ...]
+
+ detections = self.model(input_tensor)
if lock:
self.lock.unlock()
# WARNING: results other than the ones related to tensor[-1] will be discarded
diff --git a/src/ui/test/test.py b/src/ui/test/test.py
index a3ada99..00c9bcd 100755
--- a/src/ui/test/test.py
+++ b/src/ui/test/test.py
@@ -270,6 +270,8 @@ class Test(Widget):
def done(self, ok=True):
self.log.info("cycle done")
+ self.data["vision"][0].pop("detections")
+ self.data["vision"][0].pop("results")
archived = Archive.archive(self.recipe, self.data, ok and self.data["ok"], overridden=self.data["overridden"])
self.log.info(f"cycle archived locally: {archived!r}")
# COUNT OK
From 66fb6f392966cee51572518f600c620ddc5022a2 Mon Sep 17 00:00:00 2001
From: stres1
Date: Fri, 29 Jul 2022 18:18:29 +0200
Subject: [PATCH 4/5] detection no-tflite ok
---
config/machine_settings/defaults.ini | 8 +-
.../recipes/termorestringente_923578.ini | 4 +-
runme.sh | 2 +-
src/components/neo_pixels.py | 4 +-
src/test/neo_lights.py | 4 +-
src/ui/test/test.py | 9 +-
src/ui/test_leak/test_leak.ui | 148 +++++++++++++++---
src/ui/test_vision/test_vision.py | 33 ++++
8 files changed, 178 insertions(+), 34 deletions(-)
diff --git a/config/machine_settings/defaults.ini b/config/machine_settings/defaults.ini
index 912cb44..2d03bab 100644
--- a/config/machine_settings/defaults.ini
+++ b/config/machine_settings/defaults.ini
@@ -9,9 +9,9 @@ exposure_time: 10000
; vertical_crop_resolution: 2048
; rotate_90_clockwise times: 0
; auto_white_balance: off
-balance_red: 1.66
+balance_red: 1.85
balance_green: 1.0
-balance_blue: 1.12
+balance_blue: 1.5
[vision_saver]
time_format: %Y-%m-%d_%H-%M-%S
@@ -43,7 +43,7 @@ port: COM1
baudrate: 9600
[vision]
-detection_threshold: 0.75
-neural_network: hs3-20000
+detection_threshold: 0.5
+neural_network: hs5-20000
; recipes_path: ./config/vision_test_recipes
diff --git a/config/vision/recipes/termorestringente_923578.ini b/config/vision/recipes/termorestringente_923578.ini
index a68160e..9f9a83d 100644
--- a/config/vision/recipes/termorestringente_923578.ini
+++ b/config/vision/recipes/termorestringente_923578.ini
@@ -22,7 +22,7 @@ instruction: CONTROLLARE PRESENZA TERMORESTRINGENTE
[markers]
[zones]
-p1: 800,850 300,100 hs-ok # HEATSINK PRESENT
+p1: 1000,500 800,800 hs-ok # HEATSINK PRESENT
[labels]
-p1: 500,600 120 0xffffffff 0xff000000 4 TERMORESTRINGENTE
+p1: 660,1200 120 0xffffffff 0xff000000 4 TERMORESTRINGENTE
diff --git a/runme.sh b/runme.sh
index bec3ef5..c707543 100755
--- a/runme.sh
+++ b/runme.sh
@@ -1,4 +1,4 @@
#!/bin/bash -e
cd "$(dirname "$0")"
source "./venv/bin/activate" || source "./venv/Scripts/activate" || :
-python -O "./src/main.py"
+python -O "./src/main.py" --no-edgetpu --no-tflite
diff --git a/src/components/neo_pixels.py b/src/components/neo_pixels.py
index 6fb296d..cf11052 100644
--- a/src/components/neo_pixels.py
+++ b/src/components/neo_pixels.py
@@ -24,6 +24,8 @@ class NeoPixels(Component):
parity=self.parity,
bytesize=self.bytesize,
)
+ time.sleep(5)
+ self.set_all_pixel_color("#000000")
def config_changed(self):
self.port = self.config[self.name]["port"]
@@ -40,7 +42,7 @@ class NeoPixels(Component):
try:
self.conn.write(int.to_bytes(pixel, length=4, byteorder="big") + bytes.fromhex(color[1:7]) + b"\n")
response = self.conn.readline()
- if response != "ok\n":
+ if response != b"ok\n":
self.log.error(response.strip())
# conn.close()
except serial.serialutil.SerialException:
diff --git a/src/test/neo_lights.py b/src/test/neo_lights.py
index 2d29090..e64e933 100644
--- a/src/test/neo_lights.py
+++ b/src/test/neo_lights.py
@@ -1,3 +1,4 @@
+import time
from ctypes import c_uint32
import serial
@@ -13,7 +14,8 @@ conn = serial.Serial(
xonxoff=False
)
pixel = C_UINT32_MAX
-color = "#ff00ff"
+time.sleep(5)
+color = "#000000"
conn.write(int.to_bytes(pixel, length=4, byteorder="big") + bytes.fromhex(color[1:7]) + b"\n")
response = conn.readline()
print(response)
diff --git a/src/ui/test/test.py b/src/ui/test/test.py
index 00c9bcd..0a3f986 100755
--- a/src/ui/test/test.py
+++ b/src/ui/test/test.py
@@ -283,6 +283,9 @@ class Test(Widget):
# LABEL PRINT
datamatrix= archived.recipe.part_number+ archived.time.strftime("%m%y")+f"{archived.id:0>5}"
dt_label=archived.time.strftime("%d/%m/%Y %H:%M:%S")
+ pmax = self.data.get("leak", [{}, {}])[0].get("step", {}).get("spec", {}).get("test_pressure", "-")
+ pmin=self.data.get("leak", [{}, {}])[0].get("results", {}).get("data", {}).get("Running test: pressure at the end of settling", "-")
+ leak=self.data.get("leak", [{}, {}])[0].get("results", {}).get("data", {}).get("Running test: measured leak", "-")
context = {
"DATAMATRIX": datamatrix,
"DATAMATRIX_TEXT": datamatrix,
@@ -291,9 +294,9 @@ class Test(Widget):
"SHIFT": str(get_shift(archived.time)),
"STATION": str(self.machine_id),
"OPERATOR": str(Users.get_session().user.username),
- "PMAX": str(self.data.get("leak", [{}, {}])[0].get("step", {}).get("spec", {}).get("test_pressure", "-")),
- "PMIN": str(self.data.get("leak", [{}, {}])[0].get("results", {}).get("data", {}).get("Running test: pressure at the end of settling", "-")),
- "LEAK": str(self.data.get("leak", [{}, {}])[0].get("results", {}).get("data", {}).get("Running test: measured leak", "-")),
+ "PMAX": f"{pmax:.3f}",
+ "PMIN": f"{pmin:.3f}",
+ "LEAK": f"{leak:.3f}",
"TFILL": str(self.data.get("leak", [{}, {}])[0].get("step", {}).get("spec", {}).get("filling_time", "-")),
"TSTAB": str(self.data.get("leak", [{}, {}])[0].get("step", {}).get("spec", {}).get("settling_time", "-")),
"TTEST": str(self.data.get("leak", [{}, {}])[0].get("step", {}).get("spec", {}).get("test_time", "-")),
diff --git a/src/ui/test_leak/test_leak.ui b/src/ui/test_leak/test_leak.ui
index 0c4e305..af9e28f 100644
--- a/src/ui/test_leak/test_leak.ui
+++ b/src/ui/test_leak/test_leak.ui
@@ -6,7 +6,7 @@
0
0
- 854
+ 980
704
@@ -31,9 +31,9 @@
- 12
- 75
- true
+ 16
+ 50
+ false
@@ -48,9 +48,9 @@
- 12
- 75
- true
+ 16
+ 50
+ false
@@ -65,9 +65,9 @@
- 12
- 75
- true
+ 16
+ 50
+ false
@@ -82,9 +82,9 @@
- 12
- 75
- true
+ 16
+ 50
+ false
@@ -97,6 +97,24 @@
-
+
+
+ 130
+ 16777215
+
+
+
+
+ 20
+ 50
+ false
+
+
+
+ background-color: rgb(255, 255, 255);
+border: 1px solid black;
+
+
-
@@ -104,6 +122,24 @@
-
+
+
+ 130
+ 16777215
+
+
+
+
+ 20
+ 50
+ false
+
+
+
+ background-color: rgb(255, 255, 255);
+border: 1px solid black;
+
+
-
@@ -113,9 +149,9 @@
- 12
- 75
- true
+ 16
+ 50
+ false
@@ -141,6 +177,24 @@
-
+
+
+ 130
+ 16777215
+
+
+
+
+ 20
+ 50
+ false
+
+
+
+ background-color: rgb(255, 255, 255);
+border: 1px solid black;
+
+
-
@@ -150,9 +204,9 @@
- 12
- 75
- true
+ 16
+ 50
+ false
@@ -165,6 +219,13 @@
-
+
+
+ 16
+ 50
+ false
+
+
mbar
@@ -172,6 +233,13 @@
-
+
+
+ 16
+ 50
+ false
+
+
mbar
@@ -179,6 +247,13 @@
-
+
+
+ 16
+ 50
+ false
+
+
mbar
@@ -188,11 +263,16 @@
- 12
- 75
- true
+ 16
+ 50
+ false
+
+ background-color: rgb(255, 255, 255);
+border: 1px solid black;
+
+
-
@@ -200,6 +280,18 @@
-
+
+
+ 16
+ 50
+ false
+
+
+
+ background-color: rgb(255, 255, 255);
+border: 1px solid black;
+
+
-
@@ -207,6 +299,18 @@
-
+
+
+ 16
+ 50
+ false
+
+
+
+ background-color: rgb(255, 255, 255);
+border: 1px solid black;
+
+
-
diff --git a/src/ui/test_vision/test_vision.py b/src/ui/test_vision/test_vision.py
index 3d1ebdf..27093f9 100644
--- a/src/ui/test_vision/test_vision.py
+++ b/src/ui/test_vision/test_vision.py
@@ -1,9 +1,18 @@
+import os
import sys
+from datetime import datetime
+import cv2
from PyQt5.QtCore import pyqtSignal
from PyQt5.QtGui import QImage, QPixmap
from ui.test_test import Test_Test
+TMP_DIR = "tmp"
+ARCHIVE_DIR = "data/vision_saves"
+INFERENCE_INPUT_W = 256
+INFERENCE_INPUT_H = 256
+
+
class Test_Vision(Test_Test):
request_frame = pyqtSignal()
@@ -27,6 +36,7 @@ class Test_Vision(Test_Test):
self.components["vision"].resume()
self.components["galaxy_camera"].resume()
self.request_frame.emit() # request first frame
+ self.save_b.clicked.connect(lambda: self.save_frame_all(position="tmp"))
def stop(self):
# disable camera-vision loop
@@ -98,3 +108,26 @@ class Test_Vision(Test_Test):
self.last.pop("render", None)
super().emit_ko()
self.components["neo_pixels"].set_all_pixel_color("#000000")
+
+ def save_frame_detection(self, position=None, date=None):
+ if date is None:
+ date = datetime.now()
+ if position == "archive":
+ save_dir = ARCHIVE_DIR
+ elif position == "tmp":
+ save_dir = TMP_DIR
+ elif position is None:
+ save_dir = self.config["image saver"]["location"]
+ else:
+ save_dir = position
+ save_dir += "/img_archive"
+ save_dir += f"/{date.strftime('%Y')}/{date.strftime('%m')}"
+ self.remove_older_images_if_needed()
+ if not os.path.exists(save_dir):
+ os.makedirs(save_dir, exist_ok=True)
+ filename = f"{save_dir}/{date.strftime('%Y-%m-%d_%H_%M_%S')}_{self.config['image saver']['suffix']}.png"
+ print(f"saving {filename}")
+ image_np_bgr = cv2.cvtColor(self.detection_image, cv2.COLOR_RGB2BGR)
+ cv2.imwrite(filename, image_np_bgr)
+ return filename
+
From 6e8a6ab806018b2c8da5c589aca9bd063dc2dbee Mon Sep 17 00:00:00 2001
From: neo-dl
Date: Fri, 29 Jul 2022 18:54:27 +0200
Subject: [PATCH 5/5] detection ok
---
config/machine_settings/hostnames.ini | 1 +
config/machine_settings/neo-dl.ini | 7 +++++++
src/components/vision.py | 9 ++++-----
src/test/detection.py | 0
4 files changed, 12 insertions(+), 5 deletions(-)
create mode 100644 config/machine_settings/neo-dl.ini
create mode 100644 src/test/detection.py
diff --git a/config/machine_settings/hostnames.ini b/config/machine_settings/hostnames.ini
index 50cc150..5bf1804 100644
--- a/config/machine_settings/hostnames.ini
+++ b/config/machine_settings/hostnames.ini
@@ -2,4 +2,5 @@
this: this
mino: mino
DESKTOP-VOCOB38: vm
+neodl-MS-7A62: neo-dl
ST-RES-1: stres1
\ No newline at end of file
diff --git a/config/machine_settings/neo-dl.ini b/config/machine_settings/neo-dl.ini
new file mode 100644
index 0000000..03c24c4
--- /dev/null
+++ b/config/machine_settings/neo-dl.ini
@@ -0,0 +1,7 @@
+[tecna_t3]
+port: /dev/ttyUSB0
+
+[neo_pixels]
+port: /dev/ttyACM0
+baudrate: 9600
+
diff --git a/src/components/vision.py b/src/components/vision.py
index f2e2665..0d6f169 100644
--- a/src/components/vision.py
+++ b/src/components/vision.py
@@ -344,7 +344,9 @@ class Vision(Component):
if self.interpreter is not None and frame.shape != self.interpreter.get_input_details()[0]["shape"][1:3]:
tensor = np.expand_dims(cv2.resize(frame, self.interpreter.get_input_details()[0]["shape"][1:3], interpolation=cv2.INTER_LINEAR), axis=0)
else:
- tensor = np.expand_dims(frame, axis=0)
+ frame_resized=cv2.resize(frame, (256,256), interpolation=cv2.INTER_LINEAR)
+ tensor = tf.convert_to_tensor(np.asarray(frame_resized))
+ tensor = tensor[tf.newaxis, ...]
# Run inference
if lock:
self.lock.lock()
@@ -391,10 +393,7 @@ class Vision(Component):
"detection_classes": [map(lambda class_id: class_id + 1, class_ids)][0:1],
}
else:
- input_tensor = tf.convert_to_tensor(np.asarray(tensor))
- #input_tensor = input_tensor[tf.newaxis, ...]
-
- detections = self.model(input_tensor)
+ detections = self.model(tensor)
if lock:
self.lock.unlock()
# WARNING: results other than the ones related to tensor[-1] will be discarded
diff --git a/src/test/detection.py b/src/test/detection.py
new file mode 100644
index 0000000..e69de29