Spaces:
Sleeping
Sleeping
Update data_types.py
Browse filesFix two Python 3.13 incompatibilities: replace mutable np.ndarray defaults in StripMeasuredData with default_factory=lambda: np.zeros(...), and remove private _is_classvar/_is_dataclass_instance imports removed from the dataclasses stdlib in 3.13
- data_types.py +13 -13
data_types.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
# -----------------------------------------------------------------------------
|
| 2 |
#
|
| 3 |
-
# This file is part of the PantoScanner distribution on:
|
| 4 |
# https://huggingface.co/spaces/swissrail/PantoScanner
|
| 5 |
#
|
| 6 |
# PantoScanner - Analytics and measurement capability for technical objects.
|
|
@@ -16,11 +16,11 @@
|
|
| 16 |
#
|
| 17 |
# This program is distributed in the hope that it will be useful,
|
| 18 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 19 |
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
| 20 |
# GNU General Public License for more details.
|
| 21 |
#
|
| 22 |
# You should have received a copy of the GNU General Public License
|
| 23 |
-
# along with this program.
|
| 24 |
#
|
| 25 |
# -----------------------------------------------------------------------------
|
| 26 |
|
|
@@ -28,7 +28,8 @@ import os
|
|
| 28 |
from datetime import datetime
|
| 29 |
import math
|
| 30 |
import numpy as np
|
| 31 |
-
|
|
|
|
| 32 |
from typing import List, Dict, Tuple
|
| 33 |
import cv2 as cv
|
| 34 |
import json
|
|
@@ -330,10 +331,11 @@ class StripMeasuredData:
|
|
| 330 |
|
| 331 |
bounding_box_a: BBoxCoordinates = field(init=True, default=False)
|
| 332 |
bounding_box_b: BBoxCoordinates = field(init=True, default=False)
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
|
|
|
| 337 |
sliding_strip_type: str = field(init=True, default=False)
|
| 338 |
|
| 339 |
img_matched_source_data: InitVar[ImageMatchedData] = field(init=True, default=False)
|
|
@@ -399,8 +401,8 @@ class ImgSyncedData:
|
|
| 399 |
class ImageSourceData:
|
| 400 |
img_file_path: str = field(init=True)
|
| 401 |
json_file_path: str = field(init=True)
|
| 402 |
-
img_array: np.ndarray = field(init=False)
|
| 403 |
-
meta_data: dict = field(init=False)
|
| 404 |
|
| 405 |
def load_source_data(self):
|
| 406 |
self.img_array = cv.imread(self.img_file_path, cv.IMREAD_ANYDEPTH)
|
|
@@ -535,6 +537,4 @@ class ApiClientPictureData: # data given to clients, attributes inherited from
|
|
| 535 |
image_location_latitude: float # not relevant now, but will be in the future, inherited from camera reference
|
| 536 |
image_location_longitude: float # not relevant now, but will be in the future, inherited from camera reference
|
| 537 |
image_location_track_ref: int # not relevant now, but will be in the future, inherited from camera reference
|
| 538 |
-
image_train_direction_of_movement: float # train heading in degrees, or +1/-1 if the given track defines direction
|
| 539 |
-
|
| 540 |
-
|
|
|
|
| 1 |
# -----------------------------------------------------------------------------
|
| 2 |
#
|
| 3 |
+
# This file is part of the PantoScanner distribution on:
|
| 4 |
# https://huggingface.co/spaces/swissrail/PantoScanner
|
| 5 |
#
|
| 6 |
# PantoScanner - Analytics and measurement capability for technical objects.
|
|
|
|
| 16 |
#
|
| 17 |
# This program is distributed in the hope that it will be useful,
|
| 18 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 19 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 20 |
# GNU General Public License for more details.
|
| 21 |
#
|
| 22 |
# You should have received a copy of the GNU General Public License
|
| 23 |
+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
| 24 |
#
|
| 25 |
# -----------------------------------------------------------------------------
|
| 26 |
|
|
|
|
| 28 |
from datetime import datetime
|
| 29 |
import math
|
| 30 |
import numpy as np
|
| 31 |
+
# FIX: _is_classvar and _is_dataclass_instance are private internals removed in Python 3.13
|
| 32 |
+
from dataclasses import dataclass, field, asdict, astuple, InitVar, fields, is_dataclass
|
| 33 |
from typing import List, Dict, Tuple
|
| 34 |
import cv2 as cv
|
| 35 |
import json
|
|
|
|
| 331 |
|
| 332 |
bounding_box_a: BBoxCoordinates = field(init=True, default=False)
|
| 333 |
bounding_box_b: BBoxCoordinates = field(init=True, default=False)
|
| 334 |
+
# FIX: np.ndarray is mutable — Python 3.13 requires default_factory instead of default
|
| 335 |
+
estimated_euler_angles: np.ndarray = field(init=True, default_factory=lambda: np.zeros((3, 1)))
|
| 336 |
+
estimated_distances: np.ndarray = field(init=True, default_factory=lambda: np.zeros((3, 1)))
|
| 337 |
+
profile_a: np.ndarray = field(init=True, default_factory=lambda: np.zeros((601, 2)))
|
| 338 |
+
profile_b: np.ndarray = field(init=True, default_factory=lambda: np.zeros((601, 2)))
|
| 339 |
sliding_strip_type: str = field(init=True, default=False)
|
| 340 |
|
| 341 |
img_matched_source_data: InitVar[ImageMatchedData] = field(init=True, default=False)
|
|
|
|
| 401 |
class ImageSourceData:
|
| 402 |
img_file_path: str = field(init=True)
|
| 403 |
json_file_path: str = field(init=True)
|
| 404 |
+
img_array: np.ndarray = field(init=False, default=None)
|
| 405 |
+
meta_data: dict = field(init=False, default_factory=dict)
|
| 406 |
|
| 407 |
def load_source_data(self):
|
| 408 |
self.img_array = cv.imread(self.img_file_path, cv.IMREAD_ANYDEPTH)
|
|
|
|
| 537 |
image_location_latitude: float # not relevant now, but will be in the future, inherited from camera reference
|
| 538 |
image_location_longitude: float # not relevant now, but will be in the future, inherited from camera reference
|
| 539 |
image_location_track_ref: int # not relevant now, but will be in the future, inherited from camera reference
|
| 540 |
+
image_train_direction_of_movement: float # train heading in degrees, or +1/-1 if the given track defines direction
|
|
|
|
|
|