radnn 0.0.7.2__py3-none-any.whl → 0.0.7.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. radnn/__init__.py +5 -4
  2. radnn/core.py +44 -28
  3. radnn/data/__init__.py +6 -0
  4. radnn/data/data_feed.py +142 -0
  5. radnn/data/dataset_base.py +3 -5
  6. radnn/data/image_dataset.py +0 -2
  7. radnn/data/preprocess/normalizer.py +7 -1
  8. radnn/data/preprocess/standardizer.py +9 -2
  9. radnn/data/sample_set.py +30 -17
  10. radnn/data/sequence_dataset.py +0 -2
  11. radnn/data/subset_type.py +39 -0
  12. radnn/data/tf_classification_data_feed.py +97 -0
  13. radnn/errors.py +29 -0
  14. radnn/evaluation/evaluate_classification.py +7 -3
  15. radnn/experiment/ml_experiment.py +29 -0
  16. radnn/experiment/ml_experiment_config.py +7 -3
  17. radnn/experiment/ml_experiment_env.py +6 -2
  18. radnn/experiment/ml_experiment_store.py +0 -1
  19. radnn/learn/learning_algorithm.py +4 -3
  20. radnn/ml_system.py +59 -19
  21. radnn/plots/plot_auto_multi_image.py +21 -12
  22. radnn/plots/plot_confusion_matrix.py +7 -4
  23. radnn/plots/plot_learning_curve.py +7 -3
  24. radnn/plots/plot_multi_scatter.py +7 -3
  25. radnn/plots/plot_roc.py +8 -4
  26. radnn/plots/plot_voronoi_2d.py +8 -5
  27. radnn/system/files/csvfile.py +8 -5
  28. radnn/system/files/fileobject.py +9 -4
  29. radnn/system/files/imgfile.py +8 -4
  30. radnn/system/files/jsonfile.py +8 -4
  31. radnn/system/files/picklefile.py +8 -4
  32. radnn/system/files/textfile.py +8 -4
  33. radnn/system/filestore.py +10 -8
  34. radnn/system/filesystem.py +7 -2
  35. radnn/system/hosts/colab_host.py +29 -0
  36. radnn/system/hosts/linux_host.py +29 -0
  37. radnn/system/hosts/windows_host.py +29 -1
  38. radnn/system/tee_logger.py +7 -3
  39. radnn/utils.py +54 -3
  40. {radnn-0.0.7.2.dist-info → radnn-0.0.7.3.dist-info}/METADATA +1 -1
  41. radnn-0.0.7.3.dist-info/RECORD +56 -0
  42. radnn-0.0.7.2.dist-info/RECORD +0 -53
  43. {radnn-0.0.7.2.dist-info → radnn-0.0.7.3.dist-info}/LICENSE.txt +0 -0
  44. {radnn-0.0.7.2.dist-info → radnn-0.0.7.3.dist-info}/WHEEL +0 -0
  45. {radnn-0.0.7.2.dist-info → radnn-0.0.7.3.dist-info}/top_level.txt +0 -0
radnn/__init__.py CHANGED
@@ -1,7 +1,8 @@
1
- # Version 0.0.3 [2025-01-25]
2
- # Version 0.0.5 [2025-01-26]
3
- # Version 0.0.6 [2025-02-04]
4
- # Version 0.0.7 [2025-02-17]
1
+ # Version 0.0.3 [2025-01-25]
2
+ # Version 0.0.5 [2025-01-26]
3
+ # Version 0.0.6 [2025-02-04]
4
+ # Version 0.0.7.2 [2025-02-17]
5
+ # Version 0.0.7.3 [2025-02-21]
5
6
  __version__ = "0.0.7"
6
7
 
7
8
  from .system import FileStore, FileSystem
radnn/core.py CHANGED
@@ -1,27 +1,37 @@
1
+ # ======================================================================================
2
+ #
3
+ # Rapid Deep Neural Networks
4
+ #
5
+ # Licensed under the MIT License
6
+ # ______________________________________________________________________________________
7
+ # ......................................................................................
8
+
9
+ # Copyright (c) 2018-2025 Pantelis I. Kaplanoglou
10
+
11
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ # of this software and associated documentation files (the "Software"), to deal
13
+ # in the Software without restriction, including without limitation the rights
14
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ # copies of the Software, and to permit persons to whom the Software is
16
+ # furnished to do so, subject to the following conditions:
17
+
18
+ # The above copyright notice and this permission notice shall be included in all
19
+ # copies or substantial portions of the Software.
20
+
21
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ # SOFTWARE.
28
+
29
+ # .......................................................................................
1
30
  import sys
2
31
  import socket
3
32
  import platform
4
33
  import subprocess
5
34
  from datetime import datetime
6
- import importlib.util
7
-
8
-
9
- # ----------------------------------------------------------------------------------------------------------------------
10
- def is_opencv_installed():
11
- return importlib.util.find_spec("cv2") is not None
12
- # ----------------------------------------------------------------------------------------------------------------------
13
- def is_tensorflow_installed():
14
- bIsInstalled = importlib.util.find_spec("tensorflow") is not None
15
- if not is_tensorflow_installed:
16
- bIsInstalled = importlib.util.find_spec("tensorflow-gpu") is not None
17
- return bIsInstalled
18
- # ----------------------------------------------------------------------------------------------------------------------
19
- def is_torch_installed():
20
- return importlib.util.find_spec("torch") is not None
21
- # ----------------------------------------------------------------------------------------------------------------------
22
-
23
-
24
-
25
35
 
26
36
  # ----------------------------------------------------------------------------------------------------------------------
27
37
  def system_name() -> str:
@@ -45,24 +55,27 @@ def shell_command_output(command_string):
45
55
 
46
56
 
47
57
 
48
-
49
- #TODO: macOS support
50
-
58
+ # ======================================================================================================================
51
59
  class MLInfrastructure(object):
52
- # ----------------------------------------------------------------------------------------------------------------------
60
+ # --------------------------------------------------------------------------------------------------------------------
53
61
  @classmethod
54
62
  def is_linux(cls):
55
- return not (cls.is_windows or cls.is_colab)
56
- # ----------------------------------------------------------------------------------------------------------------------
63
+ return not (cls.is_windows or cls.is_colab or cls.is_macos())
64
+ # --------------------------------------------------------------------------------------------------------------------
57
65
  @classmethod
58
66
  def is_windows(cls):
59
67
  sPlatform = platform.system()
60
68
  return (sPlatform == "Windows")
61
- # ----------------------------------------------------------------------------------------------------------------------
69
+ # --------------------------------------------------------------------------------------------------------------------
62
70
  @classmethod
63
71
  def is_colab(cls):
64
72
  return "google.colab" in sys.modules
65
- # ----------------------------------------------------------------------------------------------------------------------
73
+ # --------------------------------------------------------------------------------------------------------------------
74
+ @classmethod
75
+ def is_macos(cls):
76
+ sPlatform = platform.system()
77
+ return (sPlatform == "Darwin")
78
+ # --------------------------------------------------------------------------------------------------------------------
66
79
  @classmethod
67
80
  def host_name(cls, is_using_ip_address=True) -> str:
68
81
  sPlatform = platform.system()
@@ -77,7 +90,10 @@ class MLInfrastructure(object):
77
90
  else:
78
91
  if sPlatform == "Windows":
79
92
  sResult = "(windows)-" + sHostName
93
+ elif sPlatform == "Darwin":
94
+ sResult = "(macos)-" + sHostName
80
95
  else:
81
96
  sResult = "(linux)-" + sHostName
82
97
  return sResult
83
- # ----------------------------------------------------------------------------------------------------------------------
98
+ # --------------------------------------------------------------------------------------------------------------------
99
+ # ======================================================================================================================
radnn/data/__init__.py CHANGED
@@ -1,4 +1,10 @@
1
1
  from .dataset_base import DataSetBase
2
2
  from .image_dataset import ImageDataSet
3
3
  from .sample_set import SampleSet
4
+ from .data_feed import DataFeed
5
+ from .subset_type import SubsetType
6
+ from .sample_set import SampleSet
7
+ from radnn import mlsys
8
+ if mlsys.is_tensorflow_installed:
9
+ from .tf_classification_data_feed import TFClassificationDataFeed
4
10
 
@@ -0,0 +1,142 @@
1
+ # ......................................................................................
2
+ # MIT License
3
+
4
+ # Copyright (c) 2019-2025 Pantelis I. Kaplanoglou
5
+
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+
13
+ # The above copyright notice and this permission notice shall be included in all
14
+ # copies or substantial portions of the Software.
15
+
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+
24
+ # ......................................................................................
25
+ from .dataset_base import DataSetBase
26
+ from .subset_type import SubsetType
27
+ from radnn.data.preprocess import Normalizer, Standardizer
28
+
29
+ class DataFeed(object):
30
+ def __init__(self, dataset: DataSetBase, subset_type):
31
+ self.subset_type: SubsetType = None
32
+ if isinstance(subset_type, SubsetType):
33
+ self.subset_type = subset_type
34
+ elif isinstance(subset_type, str):
35
+ self.subset_type = SubsetType(subset_type)
36
+ else:
37
+ self.subset_type = None
38
+
39
+ self.dataset = dataset
40
+ self.feed = None
41
+ self.pipeline_objects = []
42
+ self.method_actions = []
43
+ self.augmentations = []
44
+
45
+ self.value_preprocessor = None
46
+ self.padding_offset = None
47
+ self.padding_target = None
48
+
49
+ self.input_shape = self.dataset.sample_shape
50
+ self.sample_count_to_shuffle = None
51
+ if self.subset_type.is_training_set:
52
+ self.sample_count_to_shuffle = self.dataset.ts_sample_count
53
+ elif self.subset_type.is_validation_set:
54
+ self.sample_count_to_shuffle = self.dataset.vs_sample_count
55
+ elif self.subset_type.is_unknown_test_set:
56
+ self.sample_count_to_shuffle = self.dataset.ut_sample_count
57
+ self.batch_size = None
58
+
59
+ self._has_mapped_preprocessing_method = False
60
+
61
+ self.feed = self.build_iterator()
62
+ self.pipeline_objects.append(self.feed)
63
+ # --------------------------------------------------------------------------------------------------------------------
64
+ def normalize(self):
65
+ self.value_preprocessor = Normalizer(self.dataset.name, self.dataset.filestore)
66
+ if self.value_preprocessor.min is None:
67
+ self.value_preprocessor.fit(self.dataset.ts_samples)
68
+ self.method_actions.append("normalize")
69
+ if not self._has_mapped_preprocessing_method:
70
+ self.feed = self.build_preprocessor(self.feed)
71
+ self.pipeline_objects.append(self.feed)
72
+ self._has_mapped_preprocessing_method = True
73
+ return self
74
+ # --------------------------------------------------------------------------------------------------------------------
75
+ def map_preprocessing(self):
76
+ if not self._has_mapped_preprocessing_method:
77
+ self.feed = self.build_preprocessor(self.feed)
78
+ self.pipeline_objects.append(self.feed)
79
+ self._has_mapped_preprocessing_method = True
80
+ # --------------------------------------------------------------------------------------------------------------------
81
+ def standardize(self, axis_for_stats=None):
82
+ self.value_preprocessor = Standardizer(self.dataset.name, self.dataset.filestore)
83
+ if self.value_preprocessor.mean is None:
84
+ self.value_preprocessor.fit(self.dataset.ts_samples, axis_for_stats=axis_for_stats)
85
+ self.method_actions.append("standardize")
86
+ self.map_preprocessing()
87
+ return self
88
+ # --------------------------------------------------------------------------------------------------------------------
89
+ def random_shuffle(self):
90
+ self.feed = self.build_random_shuffler(self.feed)
91
+ self.pipeline_objects.append(self.feed)
92
+ return self
93
+ # --------------------------------------------------------------------------------------------------------------------
94
+ def batch(self, batch_size):
95
+ self.batch_size = batch_size
96
+ self.feed = self.build_minibatch_maker(self.feed)
97
+ self.pipeline_objects.append(self.feed)
98
+ return self
99
+ # --------------------------------------------------------------------------------------------------------------------
100
+ def augment_crop(self, padding_offset):
101
+ self.padding_offset = padding_offset
102
+ assert self.dataset.sample_shape is not None, "You should define the images input shape on the dataset"
103
+ self.padding_target = self.dataset.sample_shape[0] + self.padding_offset
104
+ self.map_preprocessing()
105
+ self.feed = self.build_augmentation(self.feed, "random_crop")
106
+ self.pipeline_objects.append(self.feed)
107
+ return self
108
+ # --------------------------------------------------------------------------------------------------------------------
109
+ def augment_flip_left_right(self):
110
+ self.map_preprocessing()
111
+ self.feed = self.build_augmentation(self.feed, "random_flip_left_right")
112
+ self.pipeline_objects.append(self.feed)
113
+ return self
114
+ # --------------------------------------------------------------------------------------------------------------------
115
+ def augment_cutout(self):
116
+ self.map_preprocessing()
117
+ self.feed = self.build_augmentation(self.feed, "random_cutout")
118
+ self.pipeline_objects.append(self.feed)
119
+ return self
120
+ # --------------------------------------------------------------------------------------------------------------------
121
+
122
+ #// To be overrided \\
123
+ # --------------------------------------------------------------------------------------------------------------------
124
+ def build_iterator(self):
125
+ return None
126
+ # --------------------------------------------------------------------------------------------------------------------
127
+ def build_preprocessor(self, feed):
128
+ return feed
129
+ # --------------------------------------------------------------------------------------------------------------------
130
+ def add_augmentation(self, augmentation_kind):
131
+ self.method_actions.add(augmentation_kind)
132
+ # --------------------------------------------------------------------------------------------------------------------
133
+ def build_random_shuffler(self, feed):
134
+ return feed
135
+ # --------------------------------------------------------------------------------------------------------------------
136
+ def build_minibatch_maker(self, feed):
137
+ return feed
138
+ # --------------------------------------------------------------------------------------------------------------------
139
+
140
+
141
+
142
+
@@ -22,8 +22,6 @@
22
22
  # SOFTWARE.
23
23
 
24
24
  # ......................................................................................
25
-
26
-
27
25
  import numpy as np
28
26
  import pandas as pd
29
27
  from sklearn.model_selection import train_test_split
@@ -56,7 +54,7 @@ class DataSetBase(object):
56
54
  elif isinstance(self.fs, FileStore):
57
55
  self.filestore = self.fs
58
56
  elif isinstance(self.fs, str):
59
- self.filestore = FileSystem(self.fs)
57
+ self.filestore = FileStore(self.fs)
60
58
  else:
61
59
  raise Exception("The parameter fs could be a path, a filestore or a filesystem")
62
60
  else:
@@ -88,6 +86,8 @@ class DataSetBase(object):
88
86
  self.ut_labels = None
89
87
  self.ut_sample_count = None
90
88
 
89
+ self.sample_shape = None
90
+
91
91
  self.card = dict()
92
92
  self.card["name"] = name
93
93
  # ................................................................
@@ -319,8 +319,6 @@ class DataSetBase(object):
319
319
  self.card["class_count"] = self.class_count
320
320
  self.card["class_names"] = self.class_names
321
321
 
322
-
323
- print(self.card)
324
322
  filestore.json.save(self.card, f"{self.name}_card.json", is_sorted_keys=False)
325
323
  # --------------------------------------------------------------------------------------------------------------------
326
324
 
@@ -22,8 +22,6 @@
22
22
  # SOFTWARE.
23
23
 
24
24
  # ......................................................................................
25
-
26
-
27
25
  import numpy as np
28
26
  from radnn import FileStore
29
27
  from .dataset_base import DataSetBase
@@ -22,7 +22,6 @@
22
22
  # SOFTWARE.
23
23
 
24
24
  # ......................................................................................
25
-
26
25
  import numpy as np
27
26
 
28
27
  '''
@@ -90,6 +89,7 @@ class Normalizer(object):
90
89
  if is_verbose:
91
90
  print(" Normalization: min/max shape:%s" % str(self.min.shape))
92
91
  self.save()
92
+ return self
93
93
  # --------------------------------------------------------------------------------------------------------------------
94
94
  def fit_transform(self, data, axis_for_stats=-1, is_recalculating=False, is_verbose=False):
95
95
  self.fit(data, axis_for_stats, is_recalculating, is_verbose)
@@ -109,3 +109,9 @@ class Normalizer(object):
109
109
  nDenormalizedData = (data * (self.max - self.min)) + self.min
110
110
  return nDenormalizedData.astype(data.dtype)
111
111
  # --------------------------------------------------------------------------------------------------------------------
112
+ def __str__(self):
113
+ return f"Normalizer: min={self.min} max={self.max}"
114
+ # --------------------------------------------------------------------------------------------------------------------
115
+ def __repr__(self):
116
+ return self.__str__()
117
+ # --------------------------------------------------------------------------------------------------------------------
@@ -22,7 +22,6 @@
22
22
  # SOFTWARE.
23
23
 
24
24
  # ......................................................................................
25
-
26
25
  import numpy as np
27
26
 
28
27
  '''
@@ -52,7 +51,7 @@ class Standardizer(object):
52
51
  dStats = {"mean": self.mean, "std": self.std}
53
52
  self.filestore.obj.save(dStats, "%s-meanstd.pkl" % self.name, is_overwriting=True)
54
53
  # --------------------------------------------------------------------------------------------------------------------
55
- def fit(self, data, axis_for_stats=-1, is_recalculating=False, is_verbose=False):
54
+ def fit(self, data, axis_for_stats=None, is_recalculating=False, is_verbose=False):
56
55
  bIsCached = False
57
56
  if (self.name is not None) and (self.filestore is not None):
58
57
  if self.mean is not None:
@@ -79,6 +78,8 @@ class Standardizer(object):
79
78
  if is_verbose:
80
79
  print(" Standardization: mean/std shape:%s" % str(self.mean.shape))
81
80
  self.save()
81
+
82
+ return self
82
83
  # --------------------------------------------------------------------------------------------------------------------
83
84
  def fit_transform(self, data, axis_for_stats=-1, is_recalculating=False, is_verbose=False):
84
85
  self.fit(data, axis_for_stats, is_recalculating, is_verbose)
@@ -98,3 +99,9 @@ class Standardizer(object):
98
99
  nNonStandardizedData = (data * self.std) + self.mean
99
100
  return nNonStandardizedData.astype(data.dtype)
100
101
  # --------------------------------------------------------------------------------------------------------------------
102
+ def __str__(self):
103
+ return f"Standardizer: mean={self.mean} std={self.std}"
104
+ # --------------------------------------------------------------------------------------------------------------------
105
+ def __repr__(self):
106
+ return self.__str__()
107
+ # --------------------------------------------------------------------------------------------------------------------
radnn/data/sample_set.py CHANGED
@@ -1,12 +1,36 @@
1
+ # ......................................................................................
2
+ # MIT License
3
+
4
+ # Copyright (c) 2019-2025 Pantelis I. Kaplanoglou
5
+
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+
13
+ # The above copyright notice and this permission notice shall be included in all
14
+ # copies or substantial portions of the Software.
15
+
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+
24
+ # ......................................................................................
1
25
  from .dataset_base import DataSetBase
2
-
26
+ from .subset_type import SubsetType
3
27
 
4
28
 
5
29
 
6
30
  class SampleSet(object):
7
31
  # --------------------------------------------------------------------------------------------------------------------
8
32
  def __init__(self, subset_type="custom", has_ids=False):
9
- self.subset_type = subset_type
33
+ self.subset_type: SubsetType = SubsetType(subset_type)
10
34
  self.parent_dataset = None
11
35
 
12
36
  self.has_ids = has_ids
@@ -21,18 +45,7 @@ class SampleSet(object):
21
45
  self._iter_counter = 0
22
46
 
23
47
  self.feed = None
24
- # --------------------------------------------------------------------------------------------------------------------
25
- @property
26
- def is_training_set(self):
27
- return (self.subset_type == "training") or (self.subset_type == "train") or (self.subset_type == "ts")
28
- # --------------------------------------------------------------------------------------------------------------------
29
- @property
30
- def is_validation_set(self):
31
- return (self.subset_type == "validation") or (self.subset_type == "val") or (self.subset_type == "vs")
32
- # --------------------------------------------------------------------------------------------------------------------
33
- @property
34
- def is_unknown_test_set(self):
35
- return (self.subset_type == "testing") or (self.subset_type == "test") or (self.subset_type == "ut")
48
+
36
49
  # --------------------------------------------------------------------------------------------------------------------
37
50
  @property
38
51
  def has_labels(self):
@@ -54,21 +67,21 @@ class SampleSet(object):
54
67
  def subset_of(self, parent_dataset: DataSetBase):
55
68
  self.parent_dataset = parent_dataset
56
69
  if self.parent_dataset is not None:
57
- if self.is_training_set:
70
+ if self.subset_type.is_training_set:
58
71
  if self.parent_dataset.ts_samples is not None:
59
72
  self.parent_dataset.ts = self
60
73
  self.ids = self.parent_dataset.ts_sample_ids
61
74
  self.samples = self.parent_dataset.ts_samples
62
75
  self.sample_count = self.parent_dataset.ts_sample_count
63
76
  self.labels = self.parent_dataset.ts_labels
64
- elif self.is_validation_set:
77
+ elif self.subset_type.is_validation_set:
65
78
  if self.parent_dataset.vs_samples is not None:
66
79
  self.parent_dataset.vs = self
67
80
  self.ids = self.parent_dataset.vs_sample_ids
68
81
  self.samples = self.parent_dataset.vs_samples
69
82
  self.sample_count = self.parent_dataset.vs_sample_count
70
83
  self.labels = self.parent_dataset.vs_labels
71
- elif self.is_unknown_test_set:
84
+ elif self.subset_type.is_unknown_test_set:
72
85
  if self.parent_dataset.ut_samples is not None:
73
86
  self.parent_dataset.ut = self
74
87
  self.ids = self.parent_dataset.ut_sample_ids
@@ -22,8 +22,6 @@
22
22
  # SOFTWARE.
23
23
 
24
24
  # ......................................................................................
25
-
26
-
27
25
  import numpy as np
28
26
  from .dataset_base import DataSetBase
29
27
 
@@ -0,0 +1,39 @@
1
+ # ......................................................................................
2
+ # MIT License
3
+
4
+ # Copyright (c) 2019-2025 Pantelis I. Kaplanoglou
5
+
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+
13
+ # The above copyright notice and this permission notice shall be included in all
14
+ # copies or substantial portions of the Software.
15
+
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+
24
+ # ......................................................................................
25
+ class SubsetType(object):
26
+ def __init__(self, name):
27
+ self.name = name
28
+
29
+ @property
30
+ def is_training_set(self):
31
+ return (self.name == "training") or (self.name == "train") or (self.name == "ts")
32
+
33
+ @property
34
+ def is_validation_set(self):
35
+ return (self.name == "validation") or (self.name == "val") or (self.name == "vs")
36
+
37
+ @property
38
+ def is_unknown_test_set(self):
39
+ return (self.name == "testing") or (self.name == "test") or (self.name == "ut")
@@ -0,0 +1,97 @@
1
+ # ======================================================================================
2
+ #
3
+ # Rapid Deep Neural Networks
4
+ #
5
+ # Licensed under the MIT License
6
+ # ______________________________________________________________________________________
7
+ # ......................................................................................
8
+
9
+ # Copyright (c) 2019-2025 Pantelis I. Kaplanoglou
10
+
11
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ # of this software and associated documentation files (the "Software"), to deal
13
+ # in the Software without restriction, including without limitation the rights
14
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ # copies of the Software, and to permit persons to whom the Software is
16
+ # furnished to do so, subject to the following conditions:
17
+
18
+ # The above copyright notice and this permission notice shall be included in all
19
+ # copies or substantial portions of the Software.
20
+
21
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ # SOFTWARE.
28
+
29
+ # ......................................................................................
30
+
31
+ import tensorflow as tf
32
+ from radnn import mlsys
33
+ from radnn.data.preprocess import Normalizer, Standardizer
34
+ from .data_feed import DataFeed
35
+
36
+ class TFClassificationDataFeed(DataFeed):
37
+ # --------------------------------------------------------------------------------------------------------------------
38
+ def do_random_crop(self, samples, labels):
39
+ tPaddedImage = tf.image.pad_to_bounding_box(samples, self.padding_offset, self.padding_offset
40
+ , self.padding_target, self.padding_target)
41
+ tResult = tf.image.random_crop(tPaddedImage, self.input_shape, seed=mlsys.seed)
42
+ print("crop", tResult)
43
+ return tResult, labels
44
+ # --------------------------------------------------------------------------------------------------------------------
45
+ def do_flip_left_right(self, samples, labels):
46
+ tResult = tf.image.random_flip_left_right(samples, seed=mlsys.seed)
47
+ print("flip", tResult)
48
+ return tResult, labels
49
+ # --------------------------------------------------------------------------------------------------------------------
50
+ def build_augmentation(self, feed, augmentation_kind):
51
+ if augmentation_kind == "random_crop":
52
+ feed = feed.map(self.do_random_crop, num_parallel_calls=8)
53
+ elif augmentation_kind == "random_flip_left_right":
54
+ feed = feed.map(self.do_flip_left_right, num_parallel_calls=8)
55
+ elif augmentation_kind == "random_cutout":
56
+ pass # //TODO: Cutout
57
+ return feed
58
+ # --------------------------------------------------------------------------------------------------------------------
59
+ def build_iterator(self):
60
+ feed = None
61
+ if self.subset_type.is_training_set:
62
+ feed = tf.data.Dataset.from_tensor_slices((self.dataset.ts_samples, self.dataset.ts_labels))
63
+ elif self.subset_type.is_validation_set:
64
+ feed = tf.data.Dataset.from_tensor_slices((self.dataset.vs_samples, self.dataset.vs_labels))
65
+ elif self.subset_type.is_unknown_test_set:
66
+ feed = tf.data.Dataset.from_tensor_slices((self.dataset.ut_samples, self.dataset.ut_labels))
67
+ return feed
68
+ # --------------------------------------------------------------------------------------------------------------------
69
+ def preprocess_normalize(self, samples, labels):
70
+ tSamples = tf.cast(samples, tf.float32)
71
+ tSamples = (tSamples - self.value_preprocessor.min) / (self.value_preprocessor.max - self.value_preprocessor.min)
72
+ tTargetsOneHot = tf.one_hot(labels, self.dataset.class_count)
73
+ return tSamples, tTargetsOneHot
74
+ # --------------------------------------------------------------------------------------------------------------------
75
+ def preprocess_standardize(self, samples, labels):
76
+ tSamples = tf.cast(samples, tf.float32)
77
+ tSamples = (tSamples - self.value_preprocessor.mean) / self.value_preprocessor.std
78
+ tTargetsOneHot = tf.one_hot(labels, self.dataset.class_count)
79
+ return tSamples, tTargetsOneHot
80
+ # --------------------------------------------------------------------------------------------------------------------
81
+ def build_preprocessor(self, feed):
82
+ if isinstance(self.value_preprocessor, Standardizer):
83
+ feed = feed.map(self.preprocess_standardize, num_parallel_calls=8)
84
+ elif isinstance(self.value_preprocessor, Normalizer):
85
+ feed = feed.map(self.preprocess_normalize, num_parallel_calls=8)
86
+ return feed
87
+ # --------------------------------------------------------------------------------------------------------------------
88
+ def build_random_shuffler(self, feed):
89
+ feed = feed.shuffle(self.sample_count_to_shuffle, seed=mlsys.seed)
90
+ return feed
91
+ # --------------------------------------------------------------------------------------------------------------------
92
+ def build_minibatch_maker(self, feed):
93
+ feed = feed.batch(self.batch_size)
94
+ return feed
95
+ # --------------------------------------------------------------------------------------------------------------------
96
+
97
+
radnn/errors.py CHANGED
@@ -1,2 +1,31 @@
1
+ # ======================================================================================
2
+ #
3
+ # Rapid Deep Neural Networks
4
+ #
5
+ # Licensed under the MIT License
6
+ # ______________________________________________________________________________________
7
+ # ......................................................................................
8
+
9
+ # Copyright (c) 2018-2025 Pantelis I. Kaplanoglou
10
+
11
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ # of this software and associated documentation files (the "Software"), to deal
13
+ # in the Software without restriction, including without limitation the rights
14
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ # copies of the Software, and to permit persons to whom the Software is
16
+ # furnished to do so, subject to the following conditions:
17
+
18
+ # The above copyright notice and this permission notice shall be included in all
19
+ # copies or substantial portions of the Software.
20
+
21
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ # SOFTWARE.
28
+
29
+ # .......................................................................................
1
30
  class Errors:
2
31
  MLSYS_NO_FILESYS = "No file system defined for the machine learning system. Create the object and assign the mlsys.filesys property."
@@ -1,7 +1,12 @@
1
+ # ======================================================================================
2
+ #
3
+ # Rapid Deep Neural Networks
4
+ #
5
+ # Licensed under the MIT License
6
+ # ______________________________________________________________________________________
1
7
  # ......................................................................................
2
- # MIT License
3
8
 
4
- # Copyright (c) 2020-2025 Pantelis I. Kaplanoglou
9
+ # Copyright (c) 2019-2025 Pantelis I. Kaplanoglou
5
10
 
6
11
  # Permission is hereby granted, free of charge, to any person obtaining a copy
7
12
  # of this software and associated documentation files (the "Software"), to deal
@@ -22,7 +27,6 @@
22
27
  # SOFTWARE.
23
28
 
24
29
  # ......................................................................................
25
-
26
30
  import numpy as np
27
31
  from sklearn import metrics
28
32