orange3-imagenets 0.0.1__tar.gz

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.
@@ -0,0 +1,19 @@
1
+ Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License
2
+
3
+ By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License ("Public License").
4
+
5
+ You may not use the material for commercial purposes.
6
+
7
+ You are free to:
8
+ - Share — copy and redistribute the material in any medium or format
9
+ - Adapt — remix, transform, and build upon the material
10
+
11
+ Under the following terms:
12
+ - Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made.
13
+ - NonCommercial — You may not use the material for commercial purposes.
14
+ - ShareAlike — If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.
15
+ - No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.
16
+
17
+ For the full license text, see: https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode
18
+
19
+ SPDX-License-Identifier: CC-BY-NC-SA-4.0
@@ -0,0 +1,62 @@
1
+ Metadata-Version: 2.4
2
+ Name: orange3-imagenets
3
+ Version: 0.0.1
4
+ Summary: A collection of Orange3 widgets for training and applying neural networks to images
5
+ Author-email: Chris Lee <github@chrislee.dhs.org>
6
+ License: CC-BY-NC-SA-4.0
7
+ Project-URL: Homepage, https://github.com/chrislee35/orange3-imagenets
8
+ Keywords: orange3 add-on
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Education
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: Programming Language :: Python :: 3 :: Only
13
+ Requires-Python: >=3.11
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Requires-Dist: Orange3>=3.39.0
17
+ Requires-Dist: orange-canvas-core>=0.1.28
18
+ Requires-Dist: orange-widget-base>=4.20.0
19
+ Requires-Dist: opencv-python>=4.12
20
+ Requires-Dist: keras>=3.10.0
21
+ Requires-Dist: tf_keras>=2.19.0
22
+ Provides-Extra: test
23
+ Requires-Dist: coverage; extra == "test"
24
+ Provides-Extra: doc
25
+ Requires-Dist: sphinx; extra == "doc"
26
+ Requires-Dist: recommonmark; extra == "doc"
27
+ Requires-Dist: sphinx_rtd_theme; extra == "doc"
28
+ Dynamic: license-file
29
+
30
+ # orange3-imagenets
31
+
32
+ This provides a collection of widgets for training and applying neural networks to images.
33
+
34
+ ## Installation
35
+
36
+ Within the Add-ons installer, click on "Add more..." and type in orange3-imagenets
37
+
38
+ ## Widgets
39
+
40
+ ### ImageNet Builder
41
+
42
+ ![Basic training workflow](imgs/training-workflow.png)
43
+
44
+ You can build a Keras model by adding layers and moving them around.
45
+
46
+ ![Simple CNN with Dense(2) output](imgs/simple-cnn-builder.png)
47
+
48
+ ![Training graph](imgs/training-graph.png)
49
+
50
+ ![Saving the ImageNet model](imgs/save-model.png)
51
+
52
+ ### Using the ImageNet
53
+
54
+ ![Basic classification workflow](imgs/classify-workflow.png)
55
+
56
+ Load the image net from a saved file.
57
+
58
+ ![Loading the model](imgs/load-model.png)
59
+
60
+ ![Viewing the classification results](imgs/classified-data-table.png)
61
+
62
+
@@ -0,0 +1,33 @@
1
+ # orange3-imagenets
2
+
3
+ This provides a collection of widgets for training and applying neural networks to images.
4
+
5
+ ## Installation
6
+
7
+ Within the Add-ons installer, click on "Add more..." and type in orange3-imagenets
8
+
9
+ ## Widgets
10
+
11
+ ### ImageNet Builder
12
+
13
+ ![Basic training workflow](imgs/training-workflow.png)
14
+
15
+ You can build a Keras model by adding layers and moving them around.
16
+
17
+ ![Simple CNN with Dense(2) output](imgs/simple-cnn-builder.png)
18
+
19
+ ![Training graph](imgs/training-graph.png)
20
+
21
+ ![Saving the ImageNet model](imgs/save-model.png)
22
+
23
+ ### Using the ImageNet
24
+
25
+ ![Basic classification workflow](imgs/classify-workflow.png)
26
+
27
+ Load the image net from a saved file.
28
+
29
+ ![Loading the model](imgs/load-model.png)
30
+
31
+ ![Viewing the classification results](imgs/classified-data-table.png)
32
+
33
+
@@ -0,0 +1,62 @@
1
+ Metadata-Version: 2.4
2
+ Name: orange3-imagenets
3
+ Version: 0.0.1
4
+ Summary: A collection of Orange3 widgets for training and applying neural networks to images
5
+ Author-email: Chris Lee <github@chrislee.dhs.org>
6
+ License: CC-BY-NC-SA-4.0
7
+ Project-URL: Homepage, https://github.com/chrislee35/orange3-imagenets
8
+ Keywords: orange3 add-on
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Education
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: Programming Language :: Python :: 3 :: Only
13
+ Requires-Python: >=3.11
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Requires-Dist: Orange3>=3.39.0
17
+ Requires-Dist: orange-canvas-core>=0.1.28
18
+ Requires-Dist: orange-widget-base>=4.20.0
19
+ Requires-Dist: opencv-python>=4.12
20
+ Requires-Dist: keras>=3.10.0
21
+ Requires-Dist: tf_keras>=2.19.0
22
+ Provides-Extra: test
23
+ Requires-Dist: coverage; extra == "test"
24
+ Provides-Extra: doc
25
+ Requires-Dist: sphinx; extra == "doc"
26
+ Requires-Dist: recommonmark; extra == "doc"
27
+ Requires-Dist: sphinx_rtd_theme; extra == "doc"
28
+ Dynamic: license-file
29
+
30
+ # orange3-imagenets
31
+
32
+ This provides a collection of widgets for training and applying neural networks to images.
33
+
34
+ ## Installation
35
+
36
+ Within the Add-ons installer, click on "Add more..." and type in orange3-imagenets
37
+
38
+ ## Widgets
39
+
40
+ ### ImageNet Builder
41
+
42
+ ![Basic training workflow](imgs/training-workflow.png)
43
+
44
+ You can build a Keras model by adding layers and moving them around.
45
+
46
+ ![Simple CNN with Dense(2) output](imgs/simple-cnn-builder.png)
47
+
48
+ ![Training graph](imgs/training-graph.png)
49
+
50
+ ![Saving the ImageNet model](imgs/save-model.png)
51
+
52
+ ### Using the ImageNet
53
+
54
+ ![Basic classification workflow](imgs/classify-workflow.png)
55
+
56
+ Load the image net from a saved file.
57
+
58
+ ![Loading the model](imgs/load-model.png)
59
+
60
+ ![Viewing the classification results](imgs/classified-data-table.png)
61
+
62
+
@@ -0,0 +1,19 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ setup.py
5
+ orange3_imagenets.egg-info/PKG-INFO
6
+ orange3_imagenets.egg-info/SOURCES.txt
7
+ orange3_imagenets.egg-info/dependency_links.txt
8
+ orange3_imagenets.egg-info/entry_points.txt
9
+ orange3_imagenets.egg-info/requires.txt
10
+ orange3_imagenets.egg-info/top_level.txt
11
+ orangecontrib/__init__.py
12
+ orangecontrib/imagenets/__init__.py
13
+ orangecontrib/imagenets/widgets/__init__.py
14
+ orangecontrib/imagenets/widgets/ow_image_augmenter.py
15
+ orangecontrib/imagenets/widgets/ow_image_train_and_score.py
16
+ orangecontrib/imagenets/widgets/ow_imagenet_builder.py
17
+ orangecontrib/imagenets/widgets/ow_imagenet_classify.py
18
+ orangecontrib/imagenets/widgets/ow_load_imagenet.py
19
+ orangecontrib/imagenets/widgets/ow_save_imagenet.py
@@ -0,0 +1,8 @@
1
+ [orange.canvas.help]
2
+ html-index = orangecontrib.imagenets.widgets:WIDGET_HELP_PATH
3
+
4
+ [orange.widgets]
5
+ imagenets = orangecontrib.imagenets.widgets
6
+
7
+ [orange3.addon]
8
+ orange3-imagenets = orangecontrib.imagenets
@@ -0,0 +1,14 @@
1
+ Orange3>=3.39.0
2
+ orange-canvas-core>=0.1.28
3
+ orange-widget-base>=4.20.0
4
+ opencv-python>=4.12
5
+ keras>=3.10.0
6
+ tf_keras>=2.19.0
7
+
8
+ [doc]
9
+ sphinx
10
+ recommonmark
11
+ sphinx_rtd_theme
12
+
13
+ [test]
14
+ coverage
@@ -0,0 +1,7 @@
1
+ datasets
2
+ dist
3
+ imgs
4
+ models
5
+ orangecontrib
6
+ tests
7
+ workflows
@@ -0,0 +1,2 @@
1
+ # namespace declaration
2
+ __import__("pkg_resources").declare_namespace(__name__)
@@ -0,0 +1,34 @@
1
+ """
2
+ ImageNet Widgets
3
+ ===============
4
+
5
+ Widgets for building and applying neural networks to images
6
+ """
7
+ import sysconfig
8
+
9
+ NAME = "ImageNets"
10
+ DESCRIPTION = "ImageNet Widgets"
11
+
12
+ ICON = "icons/imagenet-orange.svg"
13
+ PRIORITY = 1000
14
+ BACKGROUND = "#99ffee"
15
+
16
+ WIDGET_HELP_PATH = (
17
+ # Used for development.
18
+ # You still need to build help pages using
19
+ # make html
20
+ # inside doc folder
21
+ ("{DEVELOP_ROOT}/doc/_build/html/index.html", None),
22
+
23
+ # Documentation included in wheel
24
+ # Correct DATA_FILES entry is needed in setup.py and documentation has to be
25
+ # built before the wheel is created.
26
+ ("{}/help/orange3-imagenet/index.html".format(sysconfig.get_path("data")),
27
+ None),
28
+
29
+ # Online documentation url, used when the local documentation is available.
30
+ # Url should point to a page with a section Widgets. This section should
31
+ # includes links to documentation pages of each widget. Matching is
32
+ # performed by comparing link caption to widget name.
33
+ ("http://orange3-imagenet.readthedocs.io/en/latest/", "")
34
+ )
@@ -0,0 +1,290 @@
1
+ from Orange.widgets import widget, settings, gui
2
+ from Orange.widgets.widget import Input, Output
3
+ from Orange.data import Table
4
+ from AnyQt.QtWidgets import QFileDialog, QVBoxLayout, QLabel, QSpinBox, QCheckBox, QPushButton, QGroupBox
5
+ from AnyQt.QtCore import Qt
6
+ from AnyQt.QtGui import QPixmap, QFont
7
+ from PIL import Image, ImageFilter
8
+ from tensorflow.keras.preprocessing.image import ImageDataGenerator, img_to_array, load_img, array_to_img
9
+ import os
10
+ import uuid
11
+ import numpy as np
12
+
13
+
14
+ class OWImageAugmenter(widget.OWWidget):
15
+ name = "Image Augmenter"
16
+ description = "Applies image augmentation techniques to a set of input images."
17
+ icon = "icons/imageaugmenter.svg"
18
+ priority = 100
19
+
20
+ class Inputs:
21
+ images = Input("Image Table", Table)
22
+
23
+ class Outputs:
24
+ augmented_images = Output("Augmented Image Table", Table)
25
+
26
+ augment_count = settings.Setting(2)
27
+ save_folder = settings.Setting('/home/chris/Downloads/test')
28
+ zoom = settings.Setting(True)
29
+ flip = settings.Setting(True)
30
+ rotate = settings.Setting(True)
31
+ shear = settings.Setting(False)
32
+ brightness = settings.Setting(False)
33
+ blur = settings.Setting(False)
34
+ gaussian_noise = settings.Setting(False)
35
+
36
+
37
+ def __init__(self):
38
+ super().__init__()
39
+
40
+ self.image_table = None
41
+ self.layout_controlArea()
42
+ self.layout_mainArea()
43
+
44
+ def layout_controlArea(self):
45
+
46
+ # UI
47
+ self.save_folder_button = gui.button(self.controlArea, self, "Select Save Folder", callback=self.select_folder)
48
+ self.folder_label = QLabel(self.save_folder)
49
+ self.controlArea.layout().addWidget(self.folder_label)
50
+
51
+ self.augment_spin = QSpinBox()
52
+ self.augment_spin.setMinimum(1)
53
+ self.augment_spin.setValue(self.augment_count)
54
+ self.augment_spin.valueChanged.connect(self.set_augment_count)
55
+ self.controlArea.layout().addWidget(QLabel("Augmentations per Image:"))
56
+ self.controlArea.layout().addWidget(self.augment_spin)
57
+
58
+ # Augmentation Options
59
+ self.zoom_cb = QCheckBox("Zoom")
60
+ self.zoom_cb.setChecked(self.zoom)
61
+ self.zoom_cb.stateChanged.connect(lambda: self.set_flag('zoom', self.zoom_cb.isChecked()))
62
+ self.controlArea.layout().addWidget(self.zoom_cb)
63
+
64
+ self.flip_cb = QCheckBox("Horizontal Flip")
65
+ self.flip_cb.setChecked(self.flip)
66
+ self.flip_cb.stateChanged.connect(lambda: self.set_flag('flip', self.flip_cb.isChecked()))
67
+ self.controlArea.layout().addWidget(self.flip_cb)
68
+
69
+ self.rotate_cb = QCheckBox("Rotation")
70
+ self.rotate_cb.setChecked(self.rotate)
71
+ self.rotate_cb.stateChanged.connect(lambda: self.set_flag('rotate', self.rotate_cb.isChecked()))
72
+ self.controlArea.layout().addWidget(self.rotate_cb)
73
+
74
+ self.shear_cb = QCheckBox("Shear")
75
+ self.shear_cb.setChecked(self.shear)
76
+ self.shear_cb.stateChanged.connect(lambda: self.set_flag('shear', self.shear_cb.isChecked()))
77
+ self.controlArea.layout().addWidget(self.shear_cb)
78
+
79
+ self.brightness_cb = QCheckBox("Brightness")
80
+ self.brightness_cb.setChecked(self.brightness)
81
+ self.brightness_cb.stateChanged.connect(lambda: self.set_flag('brightness', self.brightness_cb.isChecked()))
82
+ self.controlArea.layout().addWidget(self.brightness_cb)
83
+
84
+ self.blur_cb = QCheckBox("Blur")
85
+ self.blur_cb.setChecked(self.blur)
86
+ self.blur_cb.stateChanged.connect(lambda: self.set_flag('blur', self.blur_cb.isChecked()))
87
+ self.controlArea.layout().addWidget(self.blur_cb)
88
+
89
+ self.gauss_cb = QCheckBox("Gaussian Noise")
90
+ self.gauss_cb.setChecked(self.gaussian_noise)
91
+ self.gauss_cb.stateChanged.connect(lambda: self.set_flag('gaussian_noise', self.gauss_cb.isChecked()))
92
+ self.controlArea.layout().addWidget(self.gauss_cb)
93
+
94
+
95
+ self.run_button = QPushButton("Generate Augmented Images")
96
+ self.run_button.clicked.connect(self.generate_augmentations)
97
+ self.controlArea.layout().addWidget(self.run_button)
98
+ self.controlArea.layout().setAlignment(Qt.AlignTop)
99
+
100
+ def layout_mainArea(self):
101
+ # Font for titles
102
+ title_font = QFont()
103
+ title_font.setBold(True)
104
+ title_font.setPointSize(12)
105
+
106
+ # ---- Before Group ----
107
+ before_group = QGroupBox("Before")
108
+ before_group.setStyleSheet("QGroupBox { font-weight: bold; border: 1px solid gray; margin-top: 10px; }")
109
+ before_layout = QVBoxLayout()
110
+
111
+ self.image_label = QLabel("No preview available")
112
+ self.image_label.setAlignment(Qt.AlignCenter)
113
+ self.image_label.setMinimumSize(256, 256)
114
+ before_layout.addWidget(self.image_label)
115
+
116
+ before_group.setLayout(before_layout)
117
+
118
+ # ---- After Group ----
119
+ after_group = QGroupBox("After")
120
+ after_group.setStyleSheet("QGroupBox { font-weight: bold; border: 1px solid gray; margin-top: 10px; }")
121
+ after_layout = QVBoxLayout()
122
+
123
+ self.aug_image_label = QLabel("No preview available")
124
+ self.aug_image_label.setAlignment(Qt.AlignCenter)
125
+ self.aug_image_label.setMinimumSize(256, 256)
126
+ after_layout.addWidget(self.aug_image_label)
127
+
128
+ after_group.setLayout(after_layout)
129
+
130
+ # ---- Add to mainArea ----
131
+ layout = self.mainArea.layout()
132
+ layout.addWidget(before_group)
133
+ layout.addWidget(after_group)
134
+
135
+ def select_folder(self):
136
+ folder = QFileDialog.getExistingDirectory(self, "Select Folder to Save Augmented Images")
137
+ if folder:
138
+ self.save_folder = folder
139
+ self.folder_label.setText(folder)
140
+
141
+ def set_augment_count(self, val):
142
+ self.augment_count = val
143
+
144
+ def set_flag(self, attr, val):
145
+ setattr(self, attr, val)
146
+ self.show_preview()
147
+
148
+ @Inputs.images
149
+ def set_data(self, table):
150
+ self.image_table = table
151
+ self.show_preview()
152
+
153
+ def apply_custom_transforms(self, img: Image.Image) -> Image.Image:
154
+ if self.blur:
155
+ img = img.filter(ImageFilter.GaussianBlur(radius=2))
156
+ if self.gaussian_noise:
157
+ arr = np.array(img).astype(np.float32)
158
+ noise = np.random.normal(0, 15, arr.shape).astype(np.float32)
159
+ arr += noise
160
+ arr = np.clip(arr, 0, 255).astype(np.uint8)
161
+ img = Image.fromarray(arr)
162
+ return img
163
+
164
+
165
+ def generate_augmentations(self):
166
+ if not self.image_table or not self.save_folder:
167
+ self.error("No image data or folder selected.")
168
+ return
169
+
170
+ self.progressBarInit()
171
+ metas = []
172
+ image_col = None
173
+ origin = None
174
+
175
+ domain = self.image_table.domain
176
+
177
+ for var in domain.metas:
178
+ if var.attributes.get("type") == "image":
179
+ image_col = var
180
+ origin = var.attributes.get("origin")
181
+ var.attributes["origin"] = self.save_folder
182
+ metas.append(var)
183
+
184
+ if not image_col:
185
+ self.error("No image column detected.")
186
+ self.progressBarFinished()
187
+ return
188
+
189
+ datagen = ImageDataGenerator(
190
+ zoom_range=0.2 if self.zoom else 0.0,
191
+ horizontal_flip=self.flip,
192
+ rotation_range=30 if self.rotate else 0,
193
+ shear_range=0.2 if self.shear else 0.0,
194
+ brightness_range=(0.7, 1.3) if self.brightness else None,
195
+ fill_mode='nearest')
196
+
197
+ new_rows = []
198
+ new_y = []
199
+
200
+ for i, row in enumerate(self.image_table):
201
+ path = row.metas[self.image_table.domain.metas.index(image_col)]
202
+ try:
203
+ img = load_img(os.path.join(origin,path))
204
+ except Exception:
205
+ print("Could not load "+os.path.join(origin,path))
206
+ continue
207
+
208
+ x = img_to_array(img)
209
+ x = x.reshape((1,) + x.shape)
210
+
211
+ gen = datagen.flow(x, batch_size=1)
212
+
213
+ for j in range(self.augment_count):
214
+ batch = next(gen)
215
+ aug_img = array_to_img(batch[0])
216
+ aug_img = self.apply_custom_transforms(aug_img)
217
+ filename = f"aug_{uuid.uuid4().hex}.png"
218
+ fullpath = os.path.join(self.save_folder, filename)
219
+ aug_img.save(fullpath)
220
+ new_row = list(row.metas)
221
+ new_row[self.image_table.domain.metas.index(image_col)] = filename
222
+ new_rows.append(new_row)
223
+ new_y.append(row.y)
224
+ self.progressBarSet((i * self.augment_count + j) / (len(self.image_table) * self.augment_count) * 100)
225
+
226
+ metas_array = np.array(new_rows, dtype=object)
227
+ new_table = Table.from_numpy(domain, X=np.empty((len(new_rows), 0)), Y=np.array(new_y), metas=metas_array)
228
+ self.Outputs.augmented_images.send(new_table)
229
+ self.progressBarFinished()
230
+
231
+ def show_preview(self):
232
+ if not self.image_table:
233
+ self.image_label.setText("No data")
234
+ return
235
+
236
+ domain = self.image_table.domain
237
+ image_col = None
238
+ origin = None
239
+
240
+ for var in domain.metas:
241
+ if var.attributes.get("type") == "image":
242
+ image_col = var
243
+ origin = var.attributes.get("origin")
244
+ break
245
+
246
+ if not image_col or not origin:
247
+ self.image_label.setText("No image found")
248
+ return
249
+
250
+ try:
251
+ # Get the first image path
252
+ path = self.image_table[0].metas[domain.metas.index(image_col)]
253
+ full_path = os.path.join(origin, path)
254
+ image = Image.open(full_path)
255
+ image.thumbnail((256, 256))
256
+
257
+ aug_image = self.augment_image(image)
258
+ image.save("/tmp/__preview.png") # Temporary path to convert to pixmap
259
+ aug_image.save('/tmp/__aug_preview.png')
260
+ pixmap = QPixmap("/tmp/__preview.png")
261
+ aug_pixmap = QPixmap("/tmp/__aug_preview.png")
262
+ self.image_label.setPixmap(pixmap)
263
+ self.aug_image_label.setPixmap(aug_pixmap)
264
+ except Exception as e:
265
+ self.image_label.setText(f"Error loading preview:\n{str(e)}")
266
+
267
+ def augment_image(self, image: Image) -> Image:
268
+ datagen = ImageDataGenerator(
269
+ zoom_range=0.2 if self.zoom else 0.0,
270
+ horizontal_flip=self.flip,
271
+ rotation_range=30 if self.rotate else 0,
272
+ shear_range=0.2 if self.shear else 0.0,
273
+ brightness_range=(0.7, 1.3) if self.brightness else None,
274
+ fill_mode='nearest')
275
+ x = img_to_array(image)
276
+ x = x.reshape((1,) + x.shape)
277
+ gen = datagen.flow(x, batch_size=1)
278
+ batch = next(gen)
279
+ aug_img = array_to_img(batch[0])
280
+ aug_img = self.apply_custom_transforms(aug_img)
281
+ return aug_img
282
+
283
+ if __name__ == "__main__":
284
+ from Orange.widgets.utils.widgetpreview import WidgetPreview
285
+ from orangecontrib.imageanalytics.import_images import ImportImages, scan
286
+ import_images = ImportImages()
287
+ data_dir = "/home/chris/Downloads/BilddatenLungenentzuendung/training/krank"
288
+ images = import_images.image_meta(scan(data_dir))
289
+ data, err = import_images(data_dir)
290
+ WidgetPreview(OWImageAugmenter).run(data)