easytorch-3.7.6
3.7.6
3.7.5
3.7.4
3.7.3
3.7.2
3.7.1
3.7.0
3.6.9
3.6.8
3.6.7
3.6.6
3.6.5
3.6.4
3.6.3
3.6.2
3.6.1
3.6.0
3.5.9
3.5.8
3.5.7
3.5.6
3.5.5
3.5.4
3.5.3
3.5.2
3.5.0
3.4.9
3.4.8
3.4.7
3.4.6
3.4.5
3.4.3
3.4.2
3.4.1
3.4.0
3.3.9
3.3.8
3.3.7
3.3.6
3.3.4
3.3.2
3.3.1
3.3.0
3.2.4
3.2.35
3.2.342
3.2.341
3.2.340
3.2.339
3.2.338
3.2.336
3.2.335
3.2.334
3.2.333
3.2.332
3.2.331
3.2.330
3.2.329
3.2.328
3.2.327
3.2.326
3.2.325
3.2.324
3.2.323
3.2.322
3.2.321
3.2.320
3.2.319
3.2.318
3.2.317
3.2.316
3.2.315
3.2.314
3.2.313
3.2.312
3.2.311
3.2.31
3.2.30
3.2.29
3.2.27
3.2.26
3.2.25
3.2.24
3.2.23
3.2.22
3.2.21
3.2.2
3.2.1
3.2.0
3.1.9
3.1.8
3.1.7
3.1.6
3.1.5
3.1.4
3.1.3
3.1.2
3.1.1
3.1.0
3.0.9
3.0.8
3.0.7
3.0.5
3.0.4
3.0.2
3.0.1
3.0.0
2.9.8
2.9.7
2.9.6
2.9.5
2.9.4
2.9.3
2.9.2
2.9.1
2.9.0
2.8.9
2.8.8
2.8.7
2.8.6
2.8.5
2.8.3
2.8.1
2.8.0
2.7.3
2.7.2
2.7.1
2.6.6
2.6.5
2.6.4
2.6.3
2.6.2
2.6.0
2.5.8
2.5.7
2.5.6
2.5.5
2.5.4
2.5.3
2.5.29
2.5.28
2.5.27
2.5.26
2.5.25
2.5.24
2.5.23
2.5.22
2.5.19
2.5.18
2.5.17
2.5.16
2.5.15
2.5.14
2.5.12
2.5.11
2.5.1
2.5.0
2.4.87
2.4.85
2.4.83
2.4.82
2.4.81
2.4.79
2.4.78
2.4.77
2.4.76
2.4.75
2.4.74
2.4.73
2.4.72
2.4.71
2.4.7
2.4.6
2.4.5
2.4.4
2.4.3
2.4.2
2.4.1
2.4.0
2.3.0
2.2.0
2.1.8
2.1.7
2.1.6
2.1.5
2.1.4
2.1.3
2.1.2
2.1.1
2.1.0
2.0.9
2.0.8
2.0.7
2.0.6
2.0.5
2.0.4
2.0.3
2.0.2
2.0.1
2.0.0
1.7.1
1.7.0
1.6.8
1.6.7
1.6.6
1.6.5
1.6.4
1.6.2
1.6.1
1.5.7
1.5.6
1.5.5
1.5.3
1.5.2
1.5.1
1.5.0
1.4.3
1.4.2
1.4.1
1.4.0
1.3.4
1.3.3
1.3.2
1.3.1
1.3
1.2
1.1
1.0
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
توضیحات
Easy Neural Network Experiments with pytorch
| ویژگی | مقدار |
|---|---|
| سیستم عامل | - |
| نام فایل | easytorch-3.7.6 |
| نام | easytorch |
| نسخه کتابخانه | 3.7.6 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | Aashis Khana1 |
| ایمیل نویسنده | sraashis@gmail.com |
| آدرس صفحه اصلی | https://github.com/sraashis/easytorch |
| آدرس اینترنتی | https://pypi.org/project/easytorch/ |
| مجوز | MIT |
## A very lightweight framework on top of PyTorch with full functionality.
#### **Just one way of doing things means no learning curve.** ✅


[](https://github.com/sraashis/easytorch/actions)

<hr />
#### Installation
1. `pip install --upgrade pip`
2. `Install latest pytorch and torchvision from` [Pytorch](https://pytorch.org/)
3. `pip install easytorch`
* [MNIST](./examples/MNIST_easytorch_CNN.ipynb) [](https://colab.research.google.com/github//sraashis/easytorch/blob/master/examples/MNIST_easytorch_CNN.ipynb)
* [Retinal fundus image transfer learning tasks.](https://github.com/sraashis/retinal-fundus-transfer)
* [Covid-19 chest x-ray classification.](https://github.com/sraashis/covidxfactory)
* [DCGAN.](https://github.com/sraashis/gan-easytorch-celeb-faces)
#### Let's start with something simple like MNIST digit classification:
```python
from easytorch import EasyTorch, ETRunner, ConfusionMatrix, ETMeter
from torchvision import datasets, transforms
import torch.nn.functional as F
import torch
from examples.models import MNISTNet
transform = transforms.Compose([
transforms.ToTensor(),
transforms.Normalize((0.1307,), (0.3081,))
])
class MNISTTrainer(ETRunner):
def _init_nn_model(self):
self.nn['model'] = MNISTNet()
def iteration(self, batch):
inputs, labels = batch[0].to(self.device['gpu']).float(), batch[1].to(self.device['gpu']).long()
out = self.nn['model'](inputs)
loss = F.nll_loss(out, labels)
_, pred = torch.max(out, 1)
meter = self.new_meter()
meter.averages.add(loss.item(), len(inputs))
meter.metrics['cfm'].add(pred, labels.float())
return {'loss': loss, 'meter': meter, 'predictions': pred}
def init_experiment_cache(self):
self.cache['log_header'] = 'Loss|Accuracy,F1,Precision,Recall'
self.cache.update(monitor_metric='f1', metric_direction='maximize')
def new_meter(self):
return ETMeter(
cfm=ConfusionMatrix(num_classes=10)
)
if __name__ == "__main__":
train_dataset = datasets.MNIST('../data', train=True, download=True, transform=transform)
val_dataset = datasets.MNIST('../data', train=False, transform=transform)
dataloader_args = {'train': {'dataset': train_dataset}, 'validation': {'dataset': val_dataset}}
runner = EasyTorch(phase='train', batch_size=512,
epochs=10, gpus=[0], dataloader_args=dataloader_args)
runner.run(MNISTTrainer)
```
### Run as:
`python script.py -ph train -b 512 -e 10 -gpus 0`
### ... with **20+** useful options. Check [here](./easytorch/config/) for full list.
<hr />
## General use case:
#### 1. Define your trainer
```python
from easytorch import ETRunner, Prf1a, ETMeter, AUCROCMetrics
class MyTrainer(ETRunner):
def _init_nn_model(self):
self.nn['model'] = NeuralNetModel(out_size=self.conf['num_class'])
def iteration(self, batch):
"""Handle a single batch"""
"""Must have loss and meter"""
meter = self.new_meter()
...
return {'loss': ..., 'meter': ..., 'predictions': ...}
def new_meter(self):
return ETMeter(
num_averages=1,
prf1a=Prf1a(),
auc=AUCROCMetrics()
)
def init_cache(self):
"""Will plot Loss in one plot, and Accuracy,F1_score in another."""
self.cache['log_header'] = 'Loss|Accuracy,F1_score'
"""Model selection using validation set if present"""
self.cache.update(monitor_metric='f1', metric_direction='maximize')
````
* Method new_meter() returns ETMeter that takes any implementation of easytorch.meter.ETMetrics. Provided ones:
* easytorch.metrics.Prf1a() for binary classification that computes accuracy,f1,precision,recall, overlap/IOU.
* easytorch.metrics.ConfusionMatrix(num_classes=...) for multiclass classification that also computes global
accuracy,f1,precision,recall.
* easytorch.metrics.AUCROCMetrics for binary ROC-AUC score.
#### 2. Define specification for your datasets:
* EasyTorch automatically splits the training data in _**data_source**_ as specified by
_**split_ratio(-spl or --split-ratio 0.7, 0.15, 0.15, for train validation and test portion)**_ OR Custom splits in
1. Text files:
* data_source = "/some/path/*.txt", where it looks for 'train.txt', 'validation.txt', and 'test.txt' if phase is
_train_, and only 'test.txt' if phase is _test_
2. Json files:
* data_source = "some/path/split.json", where each split key has list of files as {'train': [], '
validation' :[], 'test':[]}
3. Just glob as data_source = "some/path/**/*.txt", must also provide split_ratio if phase = _train_
```python
from easytorch import ETDataset
class MyDataset(ETDataset):
def load_index(self, file):
"""(Optional) Load/Process something and add to diskcache as:
self.diskcahe.add(file, value)"""
"""This method runs in multiple processes by default"""
self.indices.append([file, 'something_extra'])
def __getitem__(self, index):
file = self.indices[index]
"""(Optional) Retrieve from diskcache as self.diskcache.get(file)"""
image = # Todo # Load file/Image.
label = # Todo # Load corresponding label.
# Extra preprocessing, if needed.
# Apply transforms, if needed.
return image, label
```
#### 3. Entry point (say main.py)
### Run as:
`python main.py -ph train -b 512 -e 10 -gpus 0`
One can also directly pass arguments as below which overrides all.
```python
from easytorch import EasyTorch
runner = EasyTorch(phase="train", batch_size=4, epochs=10,
gpus=[0], num_channel=1,
num_class=2, data_source="<some_data>/data_split.json")
runner.run(MyTrainer, MyDataset)
```
### All the best! Cheers! 🎉
#### Cite the following papers if you use this library:
```
@article{deepdyn_10.3389/fcomp.2020.00035,
title = {Dynamic Deep Networks for Retinal Vessel Segmentation},
author = {Khanal, Aashis and Estrada, Rolando},
year = 2020,
journal = {Frontiers in Computer Science},
volume = 2,
pages = 35,
doi = {10.3389/fcomp.2020.00035},
issn = {2624-9898}
}
@misc{2202.02382,
Author = {Aashis Khanal and Saeid Motevali and Rolando Estrada},
Title = {Fully Automated Tree Topology Estimation and Artery-Vein Classification},
Year = {2022},
Eprint = {arXiv:2202.02382},
}
```
### Feature Higlights:
* DataHandle that is always available, and decoupled from other modules enabling easy
customization ([ETDataHandle](easytorch/data/data.py)).
* Use custom & complex data handling mechanism.
* Simple lightweight logger/plotter.
* **Plot:** set log_header = 'Loss,F1,Accuracy' to plot in same plot or set log_header = 'Loss|F1,Accuracy' to plot
Loss in one plot, and F1,Accuracy in another plot.
* **Logs:** all arguments/generated data will be saved in logs.json file after the experiment finishes.
* Gradient accumulation, automatic logging/plotting, model checkpointing, save everything.
* Multiple metrics implementation at easytorch.metrics: Precision, Recall, Accuracy, Overlap, F1, ROC-AUC, Confusion
matrix
* **For advanced training with multiple networks, and complex training steps,
click [here](assets/AdvancedTraining.md):**
* **Implement custom metrics as [here](assets/CustomMetrics.md).**
نحوه نصب
نصب پکیج whl easytorch-3.7.6:
pip install easytorch-3.7.6.whl
نصب پکیج tar.gz easytorch-3.7.6:
pip install easytorch-3.7.6.tar.gz