hyso 0.1.0__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.
hyso-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 <Huseyin Dogan>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
hyso-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,144 @@
1
+ Metadata-Version: 2.4
2
+ Name: hyso
3
+ Version: 0.1.0
4
+ Summary: Hyso: Custom CNN models, SE/CBAM blocks, callbacks, and augmentations
5
+ Home-page: https://github.com/huseyin-dgn/hyso
6
+ Author: Huseyin Dogan
7
+ Author-email: hdgn5838@gmial.com
8
+ License: MIT
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.8
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: torch>=1.13
16
+ Requires-Dist: torchvision>=0.14
17
+ Requires-Dist: numpy
18
+ Requires-Dist: matplotlib
19
+ Requires-Dist: seaborn
20
+ Requires-Dist: scikit-learn
21
+ Requires-Dist: tqdm
22
+ Dynamic: license-file
23
+
24
+ # Hyso
25
+
26
+ Hyso is a PyTorch-based deep learning library designed for **CNN + Bottleneck Residual + CBAM** architectures. It simplifies building, training, and evaluating image classification models with integrated callbacks and data augmentation.
27
+
28
+ ## Project Structure
29
+
30
+ ````bash
31
+ hyso/
32
+ │
33
+ ├─ hyso/
34
+ │ ├─ models/
35
+ │ │ ├─ bcam_model.py # CNNWithBottleneckResidualCBAM
36
+ │ │ └─ bcam_fit.py # BCAMWithFit (fit + callbacks)
37
+ │ │
38
+ │ ├─ augmentation/
39
+ │ │ └─ get_loaders.py # Data loader and augmentations
40
+ │ │
41
+ │ ├─ callbacks/
42
+ │ │ └─ callbacks.py # EarlyStopping, ModelCheckpoint, LRSchedulerCallback
43
+ │ │
44
+ │ └─ init.py
45
+ │
46
+ ├─ setup.py # Installation script
47
+ └─ README.md # Project documentation
48
+
49
+
50
+ ---
51
+
52
+ ## Features
53
+
54
+ - CNN with **Bottleneck Residual + CBAM** blocks
55
+ - `fit()` and `callbacks()` integration for simplified training
56
+ - EarlyStopping, ModelCheckpoint, and LR Scheduler support
57
+ - Flexible data loading and augmentation via `get_loaders()`
58
+ - EMA support for smoother training (optional)
59
+
60
+ ---
61
+
62
+ ## Installation
63
+
64
+ ### From PyPI (future)
65
+ ```bash
66
+ pip install hyso
67
+
68
+ ````
69
+
70
+ ## From GitHub
71
+
72
+ git clone https://github.com/yourusername/hyso.git
73
+ cd hyso
74
+ pip install .
75
+
76
+ ## Usage
77
+
78
+ ```python
79
+ from hyso.models.bcam_fit import BCAMWithFit
80
+ from hyso.augmentation.get_loaders import get_loaders
81
+
82
+ # ---------------- Dataset ----------------
83
+ train_loader, val_loader = get_loaders(
84
+ train_path="path/to/train",
85
+ val_path="path/to/val",
86
+ batch_size=64,
87
+ img_size=(32,32),
88
+ augment="advanced",
89
+ channels=3
90
+ )
91
+
92
+ # ---------------- Model ----------------
93
+ model = BCAMWithFit(input_channels=3, num_classes=10)
94
+
95
+ # ---------------- Training ----------------
96
+ model.fit(
97
+ train_loader=train_loader,
98
+ val_loader=val_loader,
99
+ scheduler="StepLR",
100
+ scheduler_params={"step_size":5,"gamma":0.5},
101
+ early_stopping=5,
102
+ checkpoint_path="best_bcam_model.pth",
103
+ epochs=20
104
+ )
105
+ ```
106
+
107
+ ## Callbacks
108
+
109
+ - Hyso supports the following callbacks to improve training:
110
+
111
+ - EarlyStopping: Stops training if validation loss stops improving.
112
+
113
+ - ModelCheckpoint: Saves the best model weights.
114
+
115
+ - LRSchedulerCallback: Automatically adjusts the learning rate based on the chosen scheduler.
116
+
117
+ Example integration:
118
+
119
+ ```python
120
+ model.callbacks(
121
+ optimizer="Adam",
122
+ scheduler="StepLR",
123
+ scheduler_params={"step_size":5,"gamma":0.5},
124
+ model_checkpoint=True,
125
+ earlystop={"patience":5, "verbose":True}
126
+ )
127
+ ```
128
+
129
+ ## Model Summary
130
+
131
+ To view a Keras-style summary of your model:
132
+
133
+ ```python
134
+ from torchsummary import summary
135
+ summary(model.model, input_size=(3, 32, 32))
136
+ ```
137
+
138
+ ## Contributing
139
+
140
+ Pull requests, bug reports, and feature requests are welcome!
141
+
142
+ ## License
143
+
144
+ No license is set. Free to use.
hyso-0.1.0/README.md ADDED
@@ -0,0 +1,121 @@
1
+ # Hyso
2
+
3
+ Hyso is a PyTorch-based deep learning library designed for **CNN + Bottleneck Residual + CBAM** architectures. It simplifies building, training, and evaluating image classification models with integrated callbacks and data augmentation.
4
+
5
+ ## Project Structure
6
+
7
+ ````bash
8
+ hyso/
9
+ │
10
+ ├─ hyso/
11
+ │ ├─ models/
12
+ │ │ ├─ bcam_model.py # CNNWithBottleneckResidualCBAM
13
+ │ │ └─ bcam_fit.py # BCAMWithFit (fit + callbacks)
14
+ │ │
15
+ │ ├─ augmentation/
16
+ │ │ └─ get_loaders.py # Data loader and augmentations
17
+ │ │
18
+ │ ├─ callbacks/
19
+ │ │ └─ callbacks.py # EarlyStopping, ModelCheckpoint, LRSchedulerCallback
20
+ │ │
21
+ │ └─ init.py
22
+ │
23
+ ├─ setup.py # Installation script
24
+ └─ README.md # Project documentation
25
+
26
+
27
+ ---
28
+
29
+ ## Features
30
+
31
+ - CNN with **Bottleneck Residual + CBAM** blocks
32
+ - `fit()` and `callbacks()` integration for simplified training
33
+ - EarlyStopping, ModelCheckpoint, and LR Scheduler support
34
+ - Flexible data loading and augmentation via `get_loaders()`
35
+ - EMA support for smoother training (optional)
36
+
37
+ ---
38
+
39
+ ## Installation
40
+
41
+ ### From PyPI (future)
42
+ ```bash
43
+ pip install hyso
44
+
45
+ ````
46
+
47
+ ## From GitHub
48
+
49
+ git clone https://github.com/yourusername/hyso.git
50
+ cd hyso
51
+ pip install .
52
+
53
+ ## Usage
54
+
55
+ ```python
56
+ from hyso.models.bcam_fit import BCAMWithFit
57
+ from hyso.augmentation.get_loaders import get_loaders
58
+
59
+ # ---------------- Dataset ----------------
60
+ train_loader, val_loader = get_loaders(
61
+ train_path="path/to/train",
62
+ val_path="path/to/val",
63
+ batch_size=64,
64
+ img_size=(32,32),
65
+ augment="advanced",
66
+ channels=3
67
+ )
68
+
69
+ # ---------------- Model ----------------
70
+ model = BCAMWithFit(input_channels=3, num_classes=10)
71
+
72
+ # ---------------- Training ----------------
73
+ model.fit(
74
+ train_loader=train_loader,
75
+ val_loader=val_loader,
76
+ scheduler="StepLR",
77
+ scheduler_params={"step_size":5,"gamma":0.5},
78
+ early_stopping=5,
79
+ checkpoint_path="best_bcam_model.pth",
80
+ epochs=20
81
+ )
82
+ ```
83
+
84
+ ## Callbacks
85
+
86
+ - Hyso supports the following callbacks to improve training:
87
+
88
+ - EarlyStopping: Stops training if validation loss stops improving.
89
+
90
+ - ModelCheckpoint: Saves the best model weights.
91
+
92
+ - LRSchedulerCallback: Automatically adjusts the learning rate based on the chosen scheduler.
93
+
94
+ Example integration:
95
+
96
+ ```python
97
+ model.callbacks(
98
+ optimizer="Adam",
99
+ scheduler="StepLR",
100
+ scheduler_params={"step_size":5,"gamma":0.5},
101
+ model_checkpoint=True,
102
+ earlystop={"patience":5, "verbose":True}
103
+ )
104
+ ```
105
+
106
+ ## Model Summary
107
+
108
+ To view a Keras-style summary of your model:
109
+
110
+ ```python
111
+ from torchsummary import summary
112
+ summary(model.model, input_size=(3, 32, 32))
113
+ ```
114
+
115
+ ## Contributing
116
+
117
+ Pull requests, bug reports, and feature requests are welcome!
118
+
119
+ ## License
120
+
121
+ No license is set. Free to use.
@@ -0,0 +1,3 @@
1
+ from .augmentation import build_transforms, get_loaders
2
+
3
+ __all__ = ["build_transforms", "get_loaders"]
@@ -0,0 +1,107 @@
1
+ # augmentation.py
2
+ from hyso.models.fit import CEMO
3
+ from torchvision import datasets, transforms
4
+ from torch.utils.data import DataLoader
5
+ import torch
6
+ import os
7
+
8
+
9
+ # ----------------------
10
+ # Transform builder
11
+ # ----------------------
12
+ def build_transforms(img_size=(224,224), augment="basic", extra_ops=None, channels=3):
13
+ """
14
+ img_size: tuple (H, W)
15
+ augment: 'basic' veya 'advanced'
16
+ extra_ops: Liste şeklinde ekstra augment işlemleri
17
+ channels: 1 veya 3 (default 3)
18
+ """
19
+ if isinstance(img_size, int):
20
+ img_size = (img_size, img_size)
21
+ H, W = img_size
22
+
23
+ ops = []
24
+
25
+ # Grayscale işlemi
26
+ if channels == 1:
27
+ ops.append(transforms.Grayscale(num_output_channels=1))
28
+
29
+ # --------------------
30
+ # Basic augment
31
+ # --------------------
32
+ basic = [
33
+ transforms.Resize((H, W)),
34
+ transforms.RandomHorizontalFlip(),
35
+ transforms.RandomRotation(10),
36
+ transforms.ColorJitter(brightness=0.2, contrast=0.2),
37
+ transforms.ToTensor()
38
+ ]
39
+
40
+ # --------------------
41
+ # Advanced augment
42
+ # --------------------
43
+ kernel_size = max(3, int(round(max(H,W)/64)) | 1)
44
+ advanced = [
45
+ transforms.RandomVerticalFlip(p=0.3),
46
+ transforms.RandomResizedCrop((H, W), scale=(0.8,1.0)),
47
+ transforms.GaussianBlur(kernel_size=(kernel_size, kernel_size), sigma=(0.1,2.0)),
48
+ transforms.RandomPerspective(distortion_scale=0.2, p=0.5),
49
+ transforms.RandomErasing(p=0.3)
50
+ ]
51
+
52
+ # Augment seçimi
53
+ if augment == "basic":
54
+ ops += basic
55
+ elif augment == "advanced":
56
+ ops += basic + advanced
57
+ else:
58
+ raise ValueError("augment sadece 'basic' veya 'advanced' olabilir.")
59
+
60
+ # Kullanıcı ekstra ops eklemek isterse
61
+ if extra_ops:
62
+ ops.extend(extra_ops)
63
+
64
+ # Normalize
65
+ if channels == 3:
66
+ ops.append(transforms.Normalize(mean=[0.485,0.456,0.406],
67
+ std=[0.229,0.224,0.225]))
68
+ else:
69
+ ops.append(transforms.Normalize(mean=[0.5], std=[0.5]))
70
+
71
+ return transforms.Compose(ops)
72
+
73
+
74
+ # ----------------------
75
+ # Dataset loader
76
+ # ----------------------
77
+ def get_loaders(train_path, val_path=None, batch_size=32, img_size=(224,224), augment="basic", extra_ops=None, num_workers=0, channels=3):
78
+ """
79
+ train_path: training klasörü (class subfolders olmalı)
80
+ val_path: validation/test klasörü (opsiyonel, yoksa train içerisinden split yapılır)
81
+ batch_size: batch size
82
+ img_size: tuple (H,W) veya int
83
+ augment: 'basic' veya 'advanced'
84
+ extra_ops: list, kullanıcı ek opsiyonları
85
+ num_workers: DataLoader için
86
+ channels: 1 veya 3
87
+ """
88
+
89
+ # ---- transform ----
90
+ train_transform = build_transforms(img_size=img_size, augment=augment, extra_ops=extra_ops, channels=channels)
91
+ val_transform = build_transforms(img_size=img_size, augment="basic", channels=channels) # artık channels geçiliyor
92
+
93
+ # ---- dataset ----
94
+ train_dataset = datasets.ImageFolder(train_path, transform=train_transform)
95
+ if val_path:
96
+ val_dataset = datasets.ImageFolder(val_path, transform=val_transform)
97
+ else:
98
+ # split train dataset
99
+ val_size = int(0.2 * len(train_dataset))
100
+ train_size = len(train_dataset) - val_size
101
+ train_dataset, val_dataset = torch.utils.data.random_split(train_dataset, [train_size, val_size])
102
+
103
+ # ---- loader ----
104
+ train_loader = DataLoader(train_dataset, batch_size=batch_size, shuffle=True, num_workers=num_workers)
105
+ val_loader = DataLoader(val_dataset, batch_size=batch_size, shuffle=False, num_workers=num_workers)
106
+
107
+ return train_loader, val_loader
File without changes
@@ -0,0 +1,53 @@
1
+ import torch
2
+
3
+ class EarlyStopping:
4
+ def __init__(self, patience=7, delta=0.0, verbose=True, restore_best_weights=True):
5
+ self.patience = patience
6
+ self.delta = delta
7
+ self.verbose = verbose
8
+ self.restore_best_weights = restore_best_weights
9
+ self.best_loss = float('inf')
10
+ self.counter = 0
11
+ self.early_stop = False
12
+ self.best_state = None
13
+
14
+ def __call__(self, val_loss, model):
15
+ if val_loss < self.best_loss - self.delta:
16
+ self.best_loss = val_loss
17
+ self.counter = 0
18
+ self.best_state = model.state_dict()
19
+ else:
20
+ self.counter += 1
21
+ if self.verbose:
22
+ print(f"EarlyStopping counter: {self.counter} out of {self.patience}")
23
+ if self.counter >= self.patience:
24
+ self.early_stop = True
25
+
26
+ def restore_weights(self, model):
27
+ if self.best_state is not None:
28
+ model.load_state_dict(self.best_state)
29
+
30
+
31
+ class ModelCheckpoint:
32
+ def __init__(self, filepath="best_model.pth", verbose=True):
33
+ self.filepath = filepath
34
+ self.verbose = verbose
35
+ self.best_loss = float('inf')
36
+
37
+ def __call__(self, epoch, model, val_loss):
38
+ if val_loss < self.best_loss:
39
+ self.best_loss = val_loss
40
+ torch.save(model.state_dict(), self.filepath)
41
+ if self.verbose:
42
+ print(f"Model saved at epoch {epoch+1} with val_loss {val_loss:.4f}")
43
+
44
+
45
+ class LRSchedulerCallback:
46
+ def __init__(self, scheduler):
47
+ self.scheduler = scheduler
48
+
49
+ def step(self, val_loss=None):
50
+ if isinstance(self.scheduler, torch.optim.lr_scheduler.ReduceLROnPlateau):
51
+ self.scheduler.step(val_loss)
52
+ else:
53
+ self.scheduler.step()
@@ -0,0 +1,144 @@
1
+ Metadata-Version: 2.4
2
+ Name: hyso
3
+ Version: 0.1.0
4
+ Summary: Hyso: Custom CNN models, SE/CBAM blocks, callbacks, and augmentations
5
+ Home-page: https://github.com/huseyin-dgn/hyso
6
+ Author: Huseyin Dogan
7
+ Author-email: hdgn5838@gmial.com
8
+ License: MIT
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.8
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: torch>=1.13
16
+ Requires-Dist: torchvision>=0.14
17
+ Requires-Dist: numpy
18
+ Requires-Dist: matplotlib
19
+ Requires-Dist: seaborn
20
+ Requires-Dist: scikit-learn
21
+ Requires-Dist: tqdm
22
+ Dynamic: license-file
23
+
24
+ # Hyso
25
+
26
+ Hyso is a PyTorch-based deep learning library designed for **CNN + Bottleneck Residual + CBAM** architectures. It simplifies building, training, and evaluating image classification models with integrated callbacks and data augmentation.
27
+
28
+ ## Project Structure
29
+
30
+ ````bash
31
+ hyso/
32
+ │
33
+ ├─ hyso/
34
+ │ ├─ models/
35
+ │ │ ├─ bcam_model.py # CNNWithBottleneckResidualCBAM
36
+ │ │ └─ bcam_fit.py # BCAMWithFit (fit + callbacks)
37
+ │ │
38
+ │ ├─ augmentation/
39
+ │ │ └─ get_loaders.py # Data loader and augmentations
40
+ │ │
41
+ │ ├─ callbacks/
42
+ │ │ └─ callbacks.py # EarlyStopping, ModelCheckpoint, LRSchedulerCallback
43
+ │ │
44
+ │ └─ init.py
45
+ │
46
+ ├─ setup.py # Installation script
47
+ └─ README.md # Project documentation
48
+
49
+
50
+ ---
51
+
52
+ ## Features
53
+
54
+ - CNN with **Bottleneck Residual + CBAM** blocks
55
+ - `fit()` and `callbacks()` integration for simplified training
56
+ - EarlyStopping, ModelCheckpoint, and LR Scheduler support
57
+ - Flexible data loading and augmentation via `get_loaders()`
58
+ - EMA support for smoother training (optional)
59
+
60
+ ---
61
+
62
+ ## Installation
63
+
64
+ ### From PyPI (future)
65
+ ```bash
66
+ pip install hyso
67
+
68
+ ````
69
+
70
+ ## From GitHub
71
+
72
+ git clone https://github.com/yourusername/hyso.git
73
+ cd hyso
74
+ pip install .
75
+
76
+ ## Usage
77
+
78
+ ```python
79
+ from hyso.models.bcam_fit import BCAMWithFit
80
+ from hyso.augmentation.get_loaders import get_loaders
81
+
82
+ # ---------------- Dataset ----------------
83
+ train_loader, val_loader = get_loaders(
84
+ train_path="path/to/train",
85
+ val_path="path/to/val",
86
+ batch_size=64,
87
+ img_size=(32,32),
88
+ augment="advanced",
89
+ channels=3
90
+ )
91
+
92
+ # ---------------- Model ----------------
93
+ model = BCAMWithFit(input_channels=3, num_classes=10)
94
+
95
+ # ---------------- Training ----------------
96
+ model.fit(
97
+ train_loader=train_loader,
98
+ val_loader=val_loader,
99
+ scheduler="StepLR",
100
+ scheduler_params={"step_size":5,"gamma":0.5},
101
+ early_stopping=5,
102
+ checkpoint_path="best_bcam_model.pth",
103
+ epochs=20
104
+ )
105
+ ```
106
+
107
+ ## Callbacks
108
+
109
+ - Hyso supports the following callbacks to improve training:
110
+
111
+ - EarlyStopping: Stops training if validation loss stops improving.
112
+
113
+ - ModelCheckpoint: Saves the best model weights.
114
+
115
+ - LRSchedulerCallback: Automatically adjusts the learning rate based on the chosen scheduler.
116
+
117
+ Example integration:
118
+
119
+ ```python
120
+ model.callbacks(
121
+ optimizer="Adam",
122
+ scheduler="StepLR",
123
+ scheduler_params={"step_size":5,"gamma":0.5},
124
+ model_checkpoint=True,
125
+ earlystop={"patience":5, "verbose":True}
126
+ )
127
+ ```
128
+
129
+ ## Model Summary
130
+
131
+ To view a Keras-style summary of your model:
132
+
133
+ ```python
134
+ from torchsummary import summary
135
+ summary(model.model, input_size=(3, 32, 32))
136
+ ```
137
+
138
+ ## Contributing
139
+
140
+ Pull requests, bug reports, and feature requests are welcome!
141
+
142
+ ## License
143
+
144
+ No license is set. Free to use.
@@ -0,0 +1,17 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ setup.cfg
5
+ hyso/augmentation/__init__.py
6
+ hyso/augmentation/augmentation.py
7
+ hyso/callbacks/__init__.py
8
+ hyso/callbacks/callbacks.py
9
+ hyso/hyso.egg-info/PKG-INFO
10
+ hyso/hyso.egg-info/SOURCES.txt
11
+ hyso/hyso.egg-info/dependency_links.txt
12
+ hyso/hyso.egg-info/requires.txt
13
+ hyso/hyso.egg-info/top_level.txt
14
+ hyso/models/WithSE.py
15
+ hyso/models/__init__.py
16
+ hyso/models/bcam.py
17
+ hyso/models/fit.py
@@ -0,0 +1,7 @@
1
+ torch>=1.13
2
+ torchvision>=0.14
3
+ numpy
4
+ matplotlib
5
+ seaborn
6
+ scikit-learn
7
+ tqdm
@@ -0,0 +1,3 @@
1
+ augmentation
2
+ callbacks
3
+ models