1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
|
%global _empty_manifest_terminate_build 0
Name: python-pywick
Version: 0.6.5
Release: 1
Summary: High-level batteries-included neural network training library for Pytorch
License: MIT License
URL: https://github.com/achaiah/pywick
Source0: https://mirrors.nju.edu.cn/pypi/web/packages/17/c5/a5b08dea4ce58acc6af2c71c14d8e19935a0792552111635445cf2d8187b/pywick-0.6.5.tar.gz
BuildArch: noarch
Requires: python3-albumentations
Requires: python3-dill
Requires: python3-h5py
Requires: python3-numpy
Requires: python3-opencv-python-headless
Requires: python3-pandas
Requires: python3-pillow
Requires: python3-prodict
Requires: python3-pycm
Requires: python3-pyyaml
Requires: python3-scipy
Requires: python3-requests
Requires: python3-scikit-image
Requires: python3-setuptools
Requires: python3-six
Requires: python3-tabulate
Requires: python3-torch
Requires: python3-torchvision
Requires: python3-tqdm
Requires: python3-yacs
Requires: python3-wheel
%description
# Pywick
<div style="text-align:center">
[](https://pywick.readthedocs.io/en/latest/)
[](https://pywick.readthedocs.io/en/latest/)
[](https://pypi.org/project/pywick/)
[](https://pywick.readthedocs.io/en/latest/)
[](https://github.com/achaiah/pywick/blob/master/LICENSE.txt)
</div>
#### High-Level Training framework for Pytorch
Pywick is a high-level Pytorch training framework that aims to get you
up and running quickly with state of the art neural networks. *Does the
world need another Pytorch framework?* Probably not. But we started this
project when no good frameworks were available and it just kept growing.
So here we are.
Pywick tries to stay on the bleeding edge of research into neural networks. If you just wish to run a vanilla CNN, this is probably
going to be overkill. However, if you want to get lost in the world of neural networks, fine-tuning and hyperparameter optimization
for months on end then this is probably the right place for you :)
Among other things Pywick includes:
- State of the art normalization, activation, loss functions and optimizers not included in the standard Pytorch library (AdaBelief, Addsign, Apollo, Eve, Lookahead, Radam, Ralamb, RangerLARS etc).
- A high-level module for training with callbacks, constraints, metrics, conditions and regularizers.
- Hundreds of popular object classification and semantic segmentation models!
- Comprehensive data loading, augmentation, transforms, and sampling capability.
- Utility tensor functions.
- Useful meters.
- Basic GridSearch (exhaustive and random).
## Docs
Hey, [check this out](https://pywick.readthedocs.io/en/latest/), we now have [docs](https://pywick.readthedocs.io/en/latest/)! They're still a work in progress though so apologies for anything that's broken.
## What's New (highlights)
### v0.6.5 - Docker all the things!
Another great improvement to the framework - docker! You can now run the 17flowers demo right out of the box!
- Grab our docker image at [docker hub](https://hub.docker.com/repository/docker/achaiah/pywick): `docker pull achaiah/pywick:latest`. Pytorch 1.8 and cuda dependencies are pre-installed.
- Run 17flowers demo with: `docker run --rm -it --ipc=host -v your_local_out_dir:/jobs/17flowers --init -e demo=true achaiah/pywick:latest`
- Or run the container in standalone mode so you can use your own data (don't forget to map your local dir to container):
```bash
docker run --rm -it \
--ipc=host \
-v <your_local_data_dir>:<container_data_dir> \
-v <your_local_out_dir>:<container_out_dir> \
--init \
achaiah/pywick:latest
```
### Older Notes
- **Oct. 11, 2021 - We thought ya might like YAML!**
- So you're saying you like **configuration files**? You're saying you like **examples** too? Well, we've got you covered! Huge release today with a configuration-based training example! All you have to do is:
- Get your favorite dataset (or download [17 flowers](https://www.robots.ox.ac.uk/~vgg/data/flowers/17/) to get started and `pywick/examples/17flowers_split.py` to convert)
- Adjust the `configs/train_classifier.yaml` file to fit your workspace
- Then simply run: `python3 train_classifier.py configs/train_classifier.yaml` and watch it train!
- **May 6, 2021**
- Many SoTA classification and segmentation models added: Swin-Transformer variants, NFNet variants (L0, L1), Halo nets, Lambda nets, ECA variants, Rexnet + others
- Many new loss functions added: RecallLoss, SoftInvDiceLoss, OhemBCEDicePenalizeBorderLoss, RMIBCEDicePenalizeBorderLoss + others
- Bug fixes
- **Jun. 15, 2020**
- 700+ models added from [rwightman's](https://github.com/rwightman/pytorch-image-models) repo via `torch.hub`! See docs for all the variants!
- Some minor bug fixes
- **Jan. 20, 2020**
- New release: 0.5.6 (minor fix from 0.5.5 for pypi)
- Mish activation function (SoTA)
- [rwightman's](https://github.com/rwightman/gen-efficientnet-pytorch) models of pretrained/ported variants for classification (44 total)
- efficientnet Tensorflow port b0-b8, with and without AP, el/em/es, cc
- mixnet L/M/S
- mobilenetv3
- mnasnet
- spnasnet
- Additional loss functions
- **Aug. 1, 2019**
- New segmentation NNs: BiSeNet, DANet, DenseASPP, DUNet, OCNet, PSANet
- New Loss Functions: Focal Tversky Loss, OHEM CrossEntropy Loss, various combination losses
- Major restructuring and standardization of NN models and loading functionality
- General bug fixes and code improvements
## Install
Pywick requires **pytorch >= 1.4**
`pip install pywick`
or specific version from git:
`pip install git+https://github.com/achaiah/pywick.git@v0.6.5`
## ModuleTrainer
The `ModuleTrainer` class provides a high-level training interface which abstracts away the training loop while providing callbacks, constraints, initializers, regularizers,
and more.
See the `train_classifier.py` example for a pretty complete configuration example. To get up and running with your own data quickly simply edit the `configs/train_classifier.yaml` file with your desired parameters and dataset location(s).
Note: <i>Dataset needs to be organized for classification where each directory name is the name of a class and contains all images pertaining to that class</i>
PyWick provides a wide range of <b>callbacks</b>, generally mimicking the interface found in `Keras`:
- `CSVLogger` - Logs epoch-level metrics to a CSV file
- [`CyclicLRScheduler`](https://github.com/bckenstler/CLR) - Cycles through min-max learning rate
- `EarlyStopping` - Provides ability to stop training early based on supplied criteria
- `History` - Keeps history of metrics etc. during the learning process
- `LambdaCallback` - Allows you to implement your own callbacks on the fly
- `LRScheduler` - Simple learning rate scheduler based on function or supplied schedule
- `ModelCheckpoint` - Comprehensive model saver
- `ReduceLROnPlateau` - Reduces learning rate (LR) when a plateau has been reached
- `SimpleModelCheckpoint` - Simple model saver
- Additionally, a `TensorboardLogger` is incredibly easy to implement via tensorboardX (now part of pytorch 1.1 release!)
```python
from pywick.callbacks import EarlyStopping
callbacks = [EarlyStopping(monitor='val_loss', patience=5)]
trainer.set_callbacks(callbacks)
```
PyWick also provides <b>regularizers</b>:
- `L1Regularizer`
- `L2Regularizer`
- `L1L2Regularizer`
and <b>constraints</b>:
- `UnitNorm`
- `MaxNorm`
- `NonNeg`
Both regularizers and constraints can be selectively applied on layers using regular expressions and the `module_filter`
argument. Constraints can be explicit (hard) constraints applied at an arbitrary batch or
epoch frequency, or they can be implicit (soft) constraints similar to regularizers
where the constraint deviation is added as a penalty to the total model loss.
```python
from pywick.constraints import MaxNorm, NonNeg
from pywick.regularizers import L1Regularizer
# hard constraint applied every 5 batches
hard_constraint = MaxNorm(value=2., frequency=5, unit='batch', module_filter='*fc*')
# implicit constraint added as a penalty term to model loss
soft_constraint = NonNeg(lagrangian=True, scale=1e-3, module_filter='*fc*')
constraints = [hard_constraint, soft_constraint]
trainer.set_constraints(constraints)
regularizers = [L1Regularizer(scale=1e-4, module_filter='*conv*')]
trainer.set_regularizers(regularizers)
```
You can also fit directly on a `torch.utils.data.DataLoader` and can have
a validation set as well :
```python
from pywick import TensorDataset
from torch.utils.data import DataLoader
train_dataset = TensorDataset(x_train, y_train)
train_loader = DataLoader(train_dataset, batch_size=32)
val_dataset = TensorDataset(x_val, y_val)
val_loader = DataLoader(val_dataset, batch_size=32)
trainer.fit_loader(loader, val_loader=val_loader, num_epoch=100)
```
## Extensive Library of Image Classification Models (most are pretrained!)
- All standard models from Pytorch:
- [**Densenet**](https://arxiv.org/abs/1608.06993)
- [**Inception v3**](https://www.cv-foundation.org/openaccess/content_cvpr_2016/papers/Szegedy_Rethinking_the_Inception_CVPR_2016_paper.pdf)
- [**MobileNet v2**](https://arxiv.org/abs/1801.04381)
- [**ResNet**](https://arxiv.org/abs/1512.03385)
- [**ShuffleNet v2**](https://arxiv.org/abs/1807.11164)
- [**SqueezeNet**](https://arxiv.org/abs/1602.07360)
- [**VGG**](https://arxiv.org/abs/1409.1556)
- [**BatchNorm Inception**](https://arxiv.org/abs/1502.03167)
- [**Deep High-Resolution Representation Learning for Human Pose Estimation**](https://arxiv.org/abs/1902.09212v1)
- [**Deep Layer Aggregation**](https://arxiv.org/abs/1707.06484)
- [**Dual Path Networks**](https://arxiv.org/abs/1707.01629)
- [**EfficientNet variants (b0-b8, el, em, es, lite1-lite4, pruned, AP/NS)**](https://arxiv.org/abs/1905.11946)
- [**ECA-Net: Efficient Channel Attention for Deep Convolutional Neural Networks**](https://arxiv.org/abs/1910.03151v4)
- [**FBResnet**](https://github.com/facebook/fb.resnet.torch)
- [**FBNet-C**](https://arxiv.org/abs/1812.03443)
- [**Inception v4**](http://arxiv.org/abs/1602.07261)
- [**InceptionResnet v2**](https://arxiv.org/abs/1602.07261)
- [**Mixnet variants (l, m, s, xl, xxl)**](https://arxiv.org/abs/1907.09595)
- [**MnasNet**](https://arxiv.org/abs/1807.11626)
- [**MobileNet V3**](https://arxiv.org/abs/1905.02244)
- [**NasNet variants (mnas, pnas, mobile)**](https://arxiv.org/abs/1707.07012)
- [**PNASNet**](https://arxiv.org/abs/1712.00559)
- [**Polynet**](https://arxiv.org/abs/1611.05725)
- [**Pyramid Resnet**](https://arxiv.org/abs/1610.02915)
- [**RegNet - Designing Network Design Spaces**](https://arxiv.org/abs/2003.13678)
- **[Resnet variants (gluon, res2net, se, ssl, tv, wide)](https://arxiv.org/abs/1512.03385)**
- [**ResNeSt: Split-Attention Networks**](https://arxiv.org/abs/2004.08955)
- [**ResNext variants (ig, se, ssl, swsl, tv)**](https://arxiv.org/abs/1611.05431)
- [**SE Net variants (gluon, resnet, resnext, inception)**](https://arxiv.org/pdf/1709.01507.pdf)
- [**SelecSLS Convolutional Net**](https://github.com/mehtadushy/SelecSLS-Pytorch)
- [**Selective Kernel Networks**](https://arxiv.org/abs/1903.06586)
- [**Semi-Supervised and Semi-Weakly Supervised ImageNet Models**](https://github.com/facebookresearch/semi-supervised-ImageNet1K-models)
- [**Single-Pass NAS Net**](https://arxiv.org/abs/1904.02877)
- [**TResNet: High Performance GPU-Dedicated Architecture**](https://arxiv.org/abs/2003.13630)
- [**Wide Resnet**](https://arxiv.org/abs/1605.07146)
- [**XCeption**](https://arxiv.org/pdf/1610.02357.pdf)
- All the newest classification models (200+) from [rwightman's repo](https://github.com/rwightman/pytorch-image-models) ECA-NFNet, GERNet, RegNet, SKResnext, SWIN-Transformer, VIT etc.)
## Image Segmentation Models
- **BiSeNet** ([Bilateral Segmentation Network for Real-time Semantic Segmentation](https://arxiv.org/abs/1808.00897))
- **DANet** ([Dual Attention Network for Scene Segmentation](https://arxiv.org/abs/1809.02983))
- **Deeplab v2** ([DeepLab: Semantic Image Segmentation with Deep Convolutional Nets, Atrous Convolution, and Fully Connected CRFs](https://arxiv.org/abs/1606.00915))
- **Deeplab v3** ([Rethinking Atrous Convolution for Semantic Image Segmentation](https://arxiv.org/abs/1706.05587))
- **DenseASPP** ([DenseASPP for Semantic Segmentation in Street Scenes](http://openaccess.thecvf.com/content_cvpr_2018/papers/Yang_DenseASPP_for_Semantic_CVPR_2018_paper.pdf))
- **DRNNet** ([Dilated Residual Networks](http://openaccess.thecvf.com/content_cvpr_2017/papers/Yu_Dilated_Residual_Networks_CVPR_2017_paper.pdf))
- **DUC, HDC** ([understanding convolution for semantic segmentation](https://arxiv.org/abs/1702.08502))
- **DUNet** ([Decoders Matter for Semantic Segmentation](https://arxiv.org/abs/1903.02120))
- **ENet** ([ENet: A Deep Neural Network Architecture for Real-Time Semantic Segmentation](https://arxiv.org/abs/1606.02147))
- **Vanilla FCN:** FCN32, FCN16, FCN8, in the versions of VGG, ResNet
and OptDenseNet respectively ([Fully convolutional networks for semantic segmentation](http://www.cv-foundation.org/openaccess/content_cvpr_2015/papers/Long_Fully_Convolutional_Networks_2015_CVPR_paper.pdf))
- **FRRN** ([Full Resolution Residual Networks for Semantic Segmentation in Street Scenes](https://arxiv.org/abs/1611.08323))
- **FusionNet** ([FusionNet in Tensorflow by Hyungjoo Andrew Cho](https://github.com/NySunShine/fusion-net))
- **GALDNet**
- **GCN** ([Large Kernel Matters](https://arxiv.org/pdf/1703.02719))
- **LinkNet** ([Link-Net](https://codeac29.github.io/projects/linknet/))
- **OCNet** ([Object Context Network for Scene Parsing](https://arxiv.org/abs/1809.00916))
- **PSPNet** ([Pyramid scene parsing network](https://arxiv.org/abs/1612.01105))
- **RefineNet** ([RefineNet](https://arxiv.org/abs/1611.06612))
- **SegNet** ([Segnet: A deep convolutional encoder-decoder architecture for image segmentation](https://arxiv.org/pdf/1511.00561))
- **Tiramisu** ([The One Hundred Layers Tiramisu: Fully Convolutional DenseNets for Semantic Segmentation](https://arxiv.org/abs/1611.09326))
- **U-Net** ([U-net: Convolutional networks for biomedical image segmentation](https://arxiv.org/abs/1505.04597))
- Additional variations of many of the above
###### To load one of these models:
[Read the docs](https://pywick.readthedocs.io/en/latest/api/pywick.models.html)
for useful details! Then dive in:
```python
# use the `get_model` utility
from pywick.models.model_utils import get_model, ModelType
model = get_model(model_type=ModelType.CLASSIFICATION, model_name='resnet18', num_classes=1000, pretrained=True)
```
For a complete list of models (including many experimental ones) you can call the `get_supported_models` method e.g.
`pywick.models.model_utils.get_supported_models(ModelType.SEGMENTATION)`
## Data Augmentation and Datasets
The PyWick package provides wide variety of good data augmentation and transformation
tools which can be applied during data loading. The package also provides the flexible
`TensorDataset`, `FolderDataset` and `MultiFolderDataset` classes to handle most dataset needs.
### Torch Transforms
##### These transforms work directly on torch tensors
- `AddChannel`
- `ChannelsFirst`
- `ChannelsLast`
- `Compose`
- `ExpandAxis`
- `Pad`
- `PadNumpy`
- `RandomChoiceCompose`
- `RandomCrop`
- `RandomFlip`
- `RandomOrder`
- `RangeNormalize`
- `Slice2D`
- `SpecialCrop`
- `StdNormalize`
- `ToFile`
- `ToNumpyType`
- `ToTensor`
- `Transpose`
- `TypeCast`
##### Additionally, we provide image-specific manipulations directly on tensors:
- `Brightness`
- `Contrast`
- `Gamma`
- `Grayscale`
- `RandomBrightness`
- `RandomChoiceBrightness`
- `RandomChoiceContrast`
- `RandomChoiceGamma`
- `RandomChoiceSaturation`
- `RandomContrast`
- `RandomGamma`
- `RandomGrayscale`
- `RandomSaturation`
- `Saturation`
##### Affine Transforms (perform affine or affine-like transforms on torch tensors)
- `RandomAffine`
- `RandomChoiceRotate`
- `RandomChoiceShear`
- `RandomChoiceTranslate`
- `RandomChoiceZoom`
- `RandomRotate`
- `RandomShear`
- `RandomSquareZoom`
- `RandomTranslate`
- `RandomZoom`
- `Rotate`
- `Shear`
- `Translate`
- `Zoom`
We also provide a class for stringing multiple affine transformations together so that only one interpolation takes place:
- `Affine`
- `AffineCompose`
##### Blur and Scramble transforms (for tensors)
- `Blur`
- `RandomChoiceBlur`
- `RandomChoiceScramble`
- `Scramble`
### Datasets and Sampling
We provide the following datasets which provide general structure and iterators for sampling from and using transforms on in-memory or out-of-memory data. In particular,
the [FolderDataset](pywick/datasets/FolderDataset.py) has been designed to fit most of your dataset needs. It has extensive options for data filtering and manipulation.
It supports loading images for classification, segmentation and even arbitrary source/target mapping. Take a good look at its documentation for more info.
- `ClonedDataset`
- `CSVDataset`
- `FolderDataset`
- `MultiFolderDataset`
- `TensorDataset`
- `tnt.BatchDataset`
- `tnt.ConcatDataset`
- `tnt.ListDataset`
- `tnt.MultiPartitionDataset`
- `tnt.ResampleDataset`
- `tnt.ShuffleDataset`
- `tnt.TensorDataset`
- `tnt.TransformDataset`
### Imbalanced Datasets
In many scenarios it is important to ensure that your traing set is properly balanced,
however, it may not be practical in real life to obtain such a perfect dataset. In these cases
you can use the `ImbalancedDatasetSampler` as a drop-in replacement for the basic sampler provided
by the DataLoader. More information can be found [here](https://github.com/ufoym/imbalanced-dataset-sampler)
```python
from pywick.samplers import ImbalancedDatasetSampler
train_loader = torch.utils.data.DataLoader(train_dataset,
sampler=ImbalancedDatasetSampler(train_dataset),
batch_size=args.batch_size, **kwargs)
```
## Utility Functions
PyWick provides a few utility functions not commonly found:
### Tensor Functions
- `th_iterproduct` (mimics itertools.product)
- `th_gather_nd` (N-dimensional version of torch.gather)
- `th_random_choice` (mimics np.random.choice)
- `th_pearsonr` (mimics scipy.stats.pearsonr)
- `th_corrcoef` (mimics np.corrcoef)
- `th_affine2d` and `th_affine3d` (affine transforms on torch.Tensors)
## Acknowledgements and References
We stand on the shoulders of (github?) giants and couldn't have done
this without the rich github ecosystem and community. This framework is
based in part on the excellent
[Torchsample](https://github.com/ncullen93/torchsample) framework
originally published by @ncullen93. Additionally, many models have been
gently borrowed/modified from @Cadene pretrained models
[repo](https://github.com/Cadene/pretrained-models.pytorch) as well as @Tramac segmentation [repo](https://github.com/Tramac/awesome-semantic-segmentation-pytorch).
##### Thank you to the following people and the projects they maintain:
- @ncullen93
- @cadene
- @deallynomore
- @recastrodiaz
- @zijundeng
- @Tramac
- And many others! (attributions listed in the codebase as they occur)
##### Thank you to the following projects from which we gently borrowed code and models
- [PyTorchNet](https://github.com/pytorch/tnt)
- [pretrained-models.pytorch](https://github.com/Cadene/pretrained-models.pytorch)
- [DeepLab_pytorch](https://github.com/doiken23/DeepLab_pytorch)
- [Pytorch for Semantic Segmentation](https://github.com/zijundeng/pytorch-semantic-segmentation)
- [Binseg Pytorch](https://github.com/saeedizadi/binseg_pytoch)
- [awesome-semantic-segmentation-pytorch](https://github.com/Tramac/awesome-semantic-segmentation-pytorch)
- And many others! (attributions listed in the codebase as they occur)
| *Thangs are broken matey! Arrr!!!* |
|-----------------------|
| We're working on this project as time permits so you might discover bugs here and there. Feel free to report them, or better yet, to submit a pull request! |
%package -n python3-pywick
Summary: High-level batteries-included neural network training library for Pytorch
Provides: python-pywick
BuildRequires: python3-devel
BuildRequires: python3-setuptools
BuildRequires: python3-pip
%description -n python3-pywick
# Pywick
<div style="text-align:center">
[](https://pywick.readthedocs.io/en/latest/)
[](https://pywick.readthedocs.io/en/latest/)
[](https://pypi.org/project/pywick/)
[](https://pywick.readthedocs.io/en/latest/)
[](https://github.com/achaiah/pywick/blob/master/LICENSE.txt)
</div>
#### High-Level Training framework for Pytorch
Pywick is a high-level Pytorch training framework that aims to get you
up and running quickly with state of the art neural networks. *Does the
world need another Pytorch framework?* Probably not. But we started this
project when no good frameworks were available and it just kept growing.
So here we are.
Pywick tries to stay on the bleeding edge of research into neural networks. If you just wish to run a vanilla CNN, this is probably
going to be overkill. However, if you want to get lost in the world of neural networks, fine-tuning and hyperparameter optimization
for months on end then this is probably the right place for you :)
Among other things Pywick includes:
- State of the art normalization, activation, loss functions and optimizers not included in the standard Pytorch library (AdaBelief, Addsign, Apollo, Eve, Lookahead, Radam, Ralamb, RangerLARS etc).
- A high-level module for training with callbacks, constraints, metrics, conditions and regularizers.
- Hundreds of popular object classification and semantic segmentation models!
- Comprehensive data loading, augmentation, transforms, and sampling capability.
- Utility tensor functions.
- Useful meters.
- Basic GridSearch (exhaustive and random).
## Docs
Hey, [check this out](https://pywick.readthedocs.io/en/latest/), we now have [docs](https://pywick.readthedocs.io/en/latest/)! They're still a work in progress though so apologies for anything that's broken.
## What's New (highlights)
### v0.6.5 - Docker all the things!
Another great improvement to the framework - docker! You can now run the 17flowers demo right out of the box!
- Grab our docker image at [docker hub](https://hub.docker.com/repository/docker/achaiah/pywick): `docker pull achaiah/pywick:latest`. Pytorch 1.8 and cuda dependencies are pre-installed.
- Run 17flowers demo with: `docker run --rm -it --ipc=host -v your_local_out_dir:/jobs/17flowers --init -e demo=true achaiah/pywick:latest`
- Or run the container in standalone mode so you can use your own data (don't forget to map your local dir to container):
```bash
docker run --rm -it \
--ipc=host \
-v <your_local_data_dir>:<container_data_dir> \
-v <your_local_out_dir>:<container_out_dir> \
--init \
achaiah/pywick:latest
```
### Older Notes
- **Oct. 11, 2021 - We thought ya might like YAML!**
- So you're saying you like **configuration files**? You're saying you like **examples** too? Well, we've got you covered! Huge release today with a configuration-based training example! All you have to do is:
- Get your favorite dataset (or download [17 flowers](https://www.robots.ox.ac.uk/~vgg/data/flowers/17/) to get started and `pywick/examples/17flowers_split.py` to convert)
- Adjust the `configs/train_classifier.yaml` file to fit your workspace
- Then simply run: `python3 train_classifier.py configs/train_classifier.yaml` and watch it train!
- **May 6, 2021**
- Many SoTA classification and segmentation models added: Swin-Transformer variants, NFNet variants (L0, L1), Halo nets, Lambda nets, ECA variants, Rexnet + others
- Many new loss functions added: RecallLoss, SoftInvDiceLoss, OhemBCEDicePenalizeBorderLoss, RMIBCEDicePenalizeBorderLoss + others
- Bug fixes
- **Jun. 15, 2020**
- 700+ models added from [rwightman's](https://github.com/rwightman/pytorch-image-models) repo via `torch.hub`! See docs for all the variants!
- Some minor bug fixes
- **Jan. 20, 2020**
- New release: 0.5.6 (minor fix from 0.5.5 for pypi)
- Mish activation function (SoTA)
- [rwightman's](https://github.com/rwightman/gen-efficientnet-pytorch) models of pretrained/ported variants for classification (44 total)
- efficientnet Tensorflow port b0-b8, with and without AP, el/em/es, cc
- mixnet L/M/S
- mobilenetv3
- mnasnet
- spnasnet
- Additional loss functions
- **Aug. 1, 2019**
- New segmentation NNs: BiSeNet, DANet, DenseASPP, DUNet, OCNet, PSANet
- New Loss Functions: Focal Tversky Loss, OHEM CrossEntropy Loss, various combination losses
- Major restructuring and standardization of NN models and loading functionality
- General bug fixes and code improvements
## Install
Pywick requires **pytorch >= 1.4**
`pip install pywick`
or specific version from git:
`pip install git+https://github.com/achaiah/pywick.git@v0.6.5`
## ModuleTrainer
The `ModuleTrainer` class provides a high-level training interface which abstracts away the training loop while providing callbacks, constraints, initializers, regularizers,
and more.
See the `train_classifier.py` example for a pretty complete configuration example. To get up and running with your own data quickly simply edit the `configs/train_classifier.yaml` file with your desired parameters and dataset location(s).
Note: <i>Dataset needs to be organized for classification where each directory name is the name of a class and contains all images pertaining to that class</i>
PyWick provides a wide range of <b>callbacks</b>, generally mimicking the interface found in `Keras`:
- `CSVLogger` - Logs epoch-level metrics to a CSV file
- [`CyclicLRScheduler`](https://github.com/bckenstler/CLR) - Cycles through min-max learning rate
- `EarlyStopping` - Provides ability to stop training early based on supplied criteria
- `History` - Keeps history of metrics etc. during the learning process
- `LambdaCallback` - Allows you to implement your own callbacks on the fly
- `LRScheduler` - Simple learning rate scheduler based on function or supplied schedule
- `ModelCheckpoint` - Comprehensive model saver
- `ReduceLROnPlateau` - Reduces learning rate (LR) when a plateau has been reached
- `SimpleModelCheckpoint` - Simple model saver
- Additionally, a `TensorboardLogger` is incredibly easy to implement via tensorboardX (now part of pytorch 1.1 release!)
```python
from pywick.callbacks import EarlyStopping
callbacks = [EarlyStopping(monitor='val_loss', patience=5)]
trainer.set_callbacks(callbacks)
```
PyWick also provides <b>regularizers</b>:
- `L1Regularizer`
- `L2Regularizer`
- `L1L2Regularizer`
and <b>constraints</b>:
- `UnitNorm`
- `MaxNorm`
- `NonNeg`
Both regularizers and constraints can be selectively applied on layers using regular expressions and the `module_filter`
argument. Constraints can be explicit (hard) constraints applied at an arbitrary batch or
epoch frequency, or they can be implicit (soft) constraints similar to regularizers
where the constraint deviation is added as a penalty to the total model loss.
```python
from pywick.constraints import MaxNorm, NonNeg
from pywick.regularizers import L1Regularizer
# hard constraint applied every 5 batches
hard_constraint = MaxNorm(value=2., frequency=5, unit='batch', module_filter='*fc*')
# implicit constraint added as a penalty term to model loss
soft_constraint = NonNeg(lagrangian=True, scale=1e-3, module_filter='*fc*')
constraints = [hard_constraint, soft_constraint]
trainer.set_constraints(constraints)
regularizers = [L1Regularizer(scale=1e-4, module_filter='*conv*')]
trainer.set_regularizers(regularizers)
```
You can also fit directly on a `torch.utils.data.DataLoader` and can have
a validation set as well :
```python
from pywick import TensorDataset
from torch.utils.data import DataLoader
train_dataset = TensorDataset(x_train, y_train)
train_loader = DataLoader(train_dataset, batch_size=32)
val_dataset = TensorDataset(x_val, y_val)
val_loader = DataLoader(val_dataset, batch_size=32)
trainer.fit_loader(loader, val_loader=val_loader, num_epoch=100)
```
## Extensive Library of Image Classification Models (most are pretrained!)
- All standard models from Pytorch:
- [**Densenet**](https://arxiv.org/abs/1608.06993)
- [**Inception v3**](https://www.cv-foundation.org/openaccess/content_cvpr_2016/papers/Szegedy_Rethinking_the_Inception_CVPR_2016_paper.pdf)
- [**MobileNet v2**](https://arxiv.org/abs/1801.04381)
- [**ResNet**](https://arxiv.org/abs/1512.03385)
- [**ShuffleNet v2**](https://arxiv.org/abs/1807.11164)
- [**SqueezeNet**](https://arxiv.org/abs/1602.07360)
- [**VGG**](https://arxiv.org/abs/1409.1556)
- [**BatchNorm Inception**](https://arxiv.org/abs/1502.03167)
- [**Deep High-Resolution Representation Learning for Human Pose Estimation**](https://arxiv.org/abs/1902.09212v1)
- [**Deep Layer Aggregation**](https://arxiv.org/abs/1707.06484)
- [**Dual Path Networks**](https://arxiv.org/abs/1707.01629)
- [**EfficientNet variants (b0-b8, el, em, es, lite1-lite4, pruned, AP/NS)**](https://arxiv.org/abs/1905.11946)
- [**ECA-Net: Efficient Channel Attention for Deep Convolutional Neural Networks**](https://arxiv.org/abs/1910.03151v4)
- [**FBResnet**](https://github.com/facebook/fb.resnet.torch)
- [**FBNet-C**](https://arxiv.org/abs/1812.03443)
- [**Inception v4**](http://arxiv.org/abs/1602.07261)
- [**InceptionResnet v2**](https://arxiv.org/abs/1602.07261)
- [**Mixnet variants (l, m, s, xl, xxl)**](https://arxiv.org/abs/1907.09595)
- [**MnasNet**](https://arxiv.org/abs/1807.11626)
- [**MobileNet V3**](https://arxiv.org/abs/1905.02244)
- [**NasNet variants (mnas, pnas, mobile)**](https://arxiv.org/abs/1707.07012)
- [**PNASNet**](https://arxiv.org/abs/1712.00559)
- [**Polynet**](https://arxiv.org/abs/1611.05725)
- [**Pyramid Resnet**](https://arxiv.org/abs/1610.02915)
- [**RegNet - Designing Network Design Spaces**](https://arxiv.org/abs/2003.13678)
- **[Resnet variants (gluon, res2net, se, ssl, tv, wide)](https://arxiv.org/abs/1512.03385)**
- [**ResNeSt: Split-Attention Networks**](https://arxiv.org/abs/2004.08955)
- [**ResNext variants (ig, se, ssl, swsl, tv)**](https://arxiv.org/abs/1611.05431)
- [**SE Net variants (gluon, resnet, resnext, inception)**](https://arxiv.org/pdf/1709.01507.pdf)
- [**SelecSLS Convolutional Net**](https://github.com/mehtadushy/SelecSLS-Pytorch)
- [**Selective Kernel Networks**](https://arxiv.org/abs/1903.06586)
- [**Semi-Supervised and Semi-Weakly Supervised ImageNet Models**](https://github.com/facebookresearch/semi-supervised-ImageNet1K-models)
- [**Single-Pass NAS Net**](https://arxiv.org/abs/1904.02877)
- [**TResNet: High Performance GPU-Dedicated Architecture**](https://arxiv.org/abs/2003.13630)
- [**Wide Resnet**](https://arxiv.org/abs/1605.07146)
- [**XCeption**](https://arxiv.org/pdf/1610.02357.pdf)
- All the newest classification models (200+) from [rwightman's repo](https://github.com/rwightman/pytorch-image-models) ECA-NFNet, GERNet, RegNet, SKResnext, SWIN-Transformer, VIT etc.)
## Image Segmentation Models
- **BiSeNet** ([Bilateral Segmentation Network for Real-time Semantic Segmentation](https://arxiv.org/abs/1808.00897))
- **DANet** ([Dual Attention Network for Scene Segmentation](https://arxiv.org/abs/1809.02983))
- **Deeplab v2** ([DeepLab: Semantic Image Segmentation with Deep Convolutional Nets, Atrous Convolution, and Fully Connected CRFs](https://arxiv.org/abs/1606.00915))
- **Deeplab v3** ([Rethinking Atrous Convolution for Semantic Image Segmentation](https://arxiv.org/abs/1706.05587))
- **DenseASPP** ([DenseASPP for Semantic Segmentation in Street Scenes](http://openaccess.thecvf.com/content_cvpr_2018/papers/Yang_DenseASPP_for_Semantic_CVPR_2018_paper.pdf))
- **DRNNet** ([Dilated Residual Networks](http://openaccess.thecvf.com/content_cvpr_2017/papers/Yu_Dilated_Residual_Networks_CVPR_2017_paper.pdf))
- **DUC, HDC** ([understanding convolution for semantic segmentation](https://arxiv.org/abs/1702.08502))
- **DUNet** ([Decoders Matter for Semantic Segmentation](https://arxiv.org/abs/1903.02120))
- **ENet** ([ENet: A Deep Neural Network Architecture for Real-Time Semantic Segmentation](https://arxiv.org/abs/1606.02147))
- **Vanilla FCN:** FCN32, FCN16, FCN8, in the versions of VGG, ResNet
and OptDenseNet respectively ([Fully convolutional networks for semantic segmentation](http://www.cv-foundation.org/openaccess/content_cvpr_2015/papers/Long_Fully_Convolutional_Networks_2015_CVPR_paper.pdf))
- **FRRN** ([Full Resolution Residual Networks for Semantic Segmentation in Street Scenes](https://arxiv.org/abs/1611.08323))
- **FusionNet** ([FusionNet in Tensorflow by Hyungjoo Andrew Cho](https://github.com/NySunShine/fusion-net))
- **GALDNet**
- **GCN** ([Large Kernel Matters](https://arxiv.org/pdf/1703.02719))
- **LinkNet** ([Link-Net](https://codeac29.github.io/projects/linknet/))
- **OCNet** ([Object Context Network for Scene Parsing](https://arxiv.org/abs/1809.00916))
- **PSPNet** ([Pyramid scene parsing network](https://arxiv.org/abs/1612.01105))
- **RefineNet** ([RefineNet](https://arxiv.org/abs/1611.06612))
- **SegNet** ([Segnet: A deep convolutional encoder-decoder architecture for image segmentation](https://arxiv.org/pdf/1511.00561))
- **Tiramisu** ([The One Hundred Layers Tiramisu: Fully Convolutional DenseNets for Semantic Segmentation](https://arxiv.org/abs/1611.09326))
- **U-Net** ([U-net: Convolutional networks for biomedical image segmentation](https://arxiv.org/abs/1505.04597))
- Additional variations of many of the above
###### To load one of these models:
[Read the docs](https://pywick.readthedocs.io/en/latest/api/pywick.models.html)
for useful details! Then dive in:
```python
# use the `get_model` utility
from pywick.models.model_utils import get_model, ModelType
model = get_model(model_type=ModelType.CLASSIFICATION, model_name='resnet18', num_classes=1000, pretrained=True)
```
For a complete list of models (including many experimental ones) you can call the `get_supported_models` method e.g.
`pywick.models.model_utils.get_supported_models(ModelType.SEGMENTATION)`
## Data Augmentation and Datasets
The PyWick package provides wide variety of good data augmentation and transformation
tools which can be applied during data loading. The package also provides the flexible
`TensorDataset`, `FolderDataset` and `MultiFolderDataset` classes to handle most dataset needs.
### Torch Transforms
##### These transforms work directly on torch tensors
- `AddChannel`
- `ChannelsFirst`
- `ChannelsLast`
- `Compose`
- `ExpandAxis`
- `Pad`
- `PadNumpy`
- `RandomChoiceCompose`
- `RandomCrop`
- `RandomFlip`
- `RandomOrder`
- `RangeNormalize`
- `Slice2D`
- `SpecialCrop`
- `StdNormalize`
- `ToFile`
- `ToNumpyType`
- `ToTensor`
- `Transpose`
- `TypeCast`
##### Additionally, we provide image-specific manipulations directly on tensors:
- `Brightness`
- `Contrast`
- `Gamma`
- `Grayscale`
- `RandomBrightness`
- `RandomChoiceBrightness`
- `RandomChoiceContrast`
- `RandomChoiceGamma`
- `RandomChoiceSaturation`
- `RandomContrast`
- `RandomGamma`
- `RandomGrayscale`
- `RandomSaturation`
- `Saturation`
##### Affine Transforms (perform affine or affine-like transforms on torch tensors)
- `RandomAffine`
- `RandomChoiceRotate`
- `RandomChoiceShear`
- `RandomChoiceTranslate`
- `RandomChoiceZoom`
- `RandomRotate`
- `RandomShear`
- `RandomSquareZoom`
- `RandomTranslate`
- `RandomZoom`
- `Rotate`
- `Shear`
- `Translate`
- `Zoom`
We also provide a class for stringing multiple affine transformations together so that only one interpolation takes place:
- `Affine`
- `AffineCompose`
##### Blur and Scramble transforms (for tensors)
- `Blur`
- `RandomChoiceBlur`
- `RandomChoiceScramble`
- `Scramble`
### Datasets and Sampling
We provide the following datasets which provide general structure and iterators for sampling from and using transforms on in-memory or out-of-memory data. In particular,
the [FolderDataset](pywick/datasets/FolderDataset.py) has been designed to fit most of your dataset needs. It has extensive options for data filtering and manipulation.
It supports loading images for classification, segmentation and even arbitrary source/target mapping. Take a good look at its documentation for more info.
- `ClonedDataset`
- `CSVDataset`
- `FolderDataset`
- `MultiFolderDataset`
- `TensorDataset`
- `tnt.BatchDataset`
- `tnt.ConcatDataset`
- `tnt.ListDataset`
- `tnt.MultiPartitionDataset`
- `tnt.ResampleDataset`
- `tnt.ShuffleDataset`
- `tnt.TensorDataset`
- `tnt.TransformDataset`
### Imbalanced Datasets
In many scenarios it is important to ensure that your traing set is properly balanced,
however, it may not be practical in real life to obtain such a perfect dataset. In these cases
you can use the `ImbalancedDatasetSampler` as a drop-in replacement for the basic sampler provided
by the DataLoader. More information can be found [here](https://github.com/ufoym/imbalanced-dataset-sampler)
```python
from pywick.samplers import ImbalancedDatasetSampler
train_loader = torch.utils.data.DataLoader(train_dataset,
sampler=ImbalancedDatasetSampler(train_dataset),
batch_size=args.batch_size, **kwargs)
```
## Utility Functions
PyWick provides a few utility functions not commonly found:
### Tensor Functions
- `th_iterproduct` (mimics itertools.product)
- `th_gather_nd` (N-dimensional version of torch.gather)
- `th_random_choice` (mimics np.random.choice)
- `th_pearsonr` (mimics scipy.stats.pearsonr)
- `th_corrcoef` (mimics np.corrcoef)
- `th_affine2d` and `th_affine3d` (affine transforms on torch.Tensors)
## Acknowledgements and References
We stand on the shoulders of (github?) giants and couldn't have done
this without the rich github ecosystem and community. This framework is
based in part on the excellent
[Torchsample](https://github.com/ncullen93/torchsample) framework
originally published by @ncullen93. Additionally, many models have been
gently borrowed/modified from @Cadene pretrained models
[repo](https://github.com/Cadene/pretrained-models.pytorch) as well as @Tramac segmentation [repo](https://github.com/Tramac/awesome-semantic-segmentation-pytorch).
##### Thank you to the following people and the projects they maintain:
- @ncullen93
- @cadene
- @deallynomore
- @recastrodiaz
- @zijundeng
- @Tramac
- And many others! (attributions listed in the codebase as they occur)
##### Thank you to the following projects from which we gently borrowed code and models
- [PyTorchNet](https://github.com/pytorch/tnt)
- [pretrained-models.pytorch](https://github.com/Cadene/pretrained-models.pytorch)
- [DeepLab_pytorch](https://github.com/doiken23/DeepLab_pytorch)
- [Pytorch for Semantic Segmentation](https://github.com/zijundeng/pytorch-semantic-segmentation)
- [Binseg Pytorch](https://github.com/saeedizadi/binseg_pytoch)
- [awesome-semantic-segmentation-pytorch](https://github.com/Tramac/awesome-semantic-segmentation-pytorch)
- And many others! (attributions listed in the codebase as they occur)
| *Thangs are broken matey! Arrr!!!* |
|-----------------------|
| We're working on this project as time permits so you might discover bugs here and there. Feel free to report them, or better yet, to submit a pull request! |
%package help
Summary: Development documents and examples for pywick
Provides: python3-pywick-doc
%description help
# Pywick
<div style="text-align:center">
[](https://pywick.readthedocs.io/en/latest/)
[](https://pywick.readthedocs.io/en/latest/)
[](https://pypi.org/project/pywick/)
[](https://pywick.readthedocs.io/en/latest/)
[](https://github.com/achaiah/pywick/blob/master/LICENSE.txt)
</div>
#### High-Level Training framework for Pytorch
Pywick is a high-level Pytorch training framework that aims to get you
up and running quickly with state of the art neural networks. *Does the
world need another Pytorch framework?* Probably not. But we started this
project when no good frameworks were available and it just kept growing.
So here we are.
Pywick tries to stay on the bleeding edge of research into neural networks. If you just wish to run a vanilla CNN, this is probably
going to be overkill. However, if you want to get lost in the world of neural networks, fine-tuning and hyperparameter optimization
for months on end then this is probably the right place for you :)
Among other things Pywick includes:
- State of the art normalization, activation, loss functions and optimizers not included in the standard Pytorch library (AdaBelief, Addsign, Apollo, Eve, Lookahead, Radam, Ralamb, RangerLARS etc).
- A high-level module for training with callbacks, constraints, metrics, conditions and regularizers.
- Hundreds of popular object classification and semantic segmentation models!
- Comprehensive data loading, augmentation, transforms, and sampling capability.
- Utility tensor functions.
- Useful meters.
- Basic GridSearch (exhaustive and random).
## Docs
Hey, [check this out](https://pywick.readthedocs.io/en/latest/), we now have [docs](https://pywick.readthedocs.io/en/latest/)! They're still a work in progress though so apologies for anything that's broken.
## What's New (highlights)
### v0.6.5 - Docker all the things!
Another great improvement to the framework - docker! You can now run the 17flowers demo right out of the box!
- Grab our docker image at [docker hub](https://hub.docker.com/repository/docker/achaiah/pywick): `docker pull achaiah/pywick:latest`. Pytorch 1.8 and cuda dependencies are pre-installed.
- Run 17flowers demo with: `docker run --rm -it --ipc=host -v your_local_out_dir:/jobs/17flowers --init -e demo=true achaiah/pywick:latest`
- Or run the container in standalone mode so you can use your own data (don't forget to map your local dir to container):
```bash
docker run --rm -it \
--ipc=host \
-v <your_local_data_dir>:<container_data_dir> \
-v <your_local_out_dir>:<container_out_dir> \
--init \
achaiah/pywick:latest
```
### Older Notes
- **Oct. 11, 2021 - We thought ya might like YAML!**
- So you're saying you like **configuration files**? You're saying you like **examples** too? Well, we've got you covered! Huge release today with a configuration-based training example! All you have to do is:
- Get your favorite dataset (or download [17 flowers](https://www.robots.ox.ac.uk/~vgg/data/flowers/17/) to get started and `pywick/examples/17flowers_split.py` to convert)
- Adjust the `configs/train_classifier.yaml` file to fit your workspace
- Then simply run: `python3 train_classifier.py configs/train_classifier.yaml` and watch it train!
- **May 6, 2021**
- Many SoTA classification and segmentation models added: Swin-Transformer variants, NFNet variants (L0, L1), Halo nets, Lambda nets, ECA variants, Rexnet + others
- Many new loss functions added: RecallLoss, SoftInvDiceLoss, OhemBCEDicePenalizeBorderLoss, RMIBCEDicePenalizeBorderLoss + others
- Bug fixes
- **Jun. 15, 2020**
- 700+ models added from [rwightman's](https://github.com/rwightman/pytorch-image-models) repo via `torch.hub`! See docs for all the variants!
- Some minor bug fixes
- **Jan. 20, 2020**
- New release: 0.5.6 (minor fix from 0.5.5 for pypi)
- Mish activation function (SoTA)
- [rwightman's](https://github.com/rwightman/gen-efficientnet-pytorch) models of pretrained/ported variants for classification (44 total)
- efficientnet Tensorflow port b0-b8, with and without AP, el/em/es, cc
- mixnet L/M/S
- mobilenetv3
- mnasnet
- spnasnet
- Additional loss functions
- **Aug. 1, 2019**
- New segmentation NNs: BiSeNet, DANet, DenseASPP, DUNet, OCNet, PSANet
- New Loss Functions: Focal Tversky Loss, OHEM CrossEntropy Loss, various combination losses
- Major restructuring and standardization of NN models and loading functionality
- General bug fixes and code improvements
## Install
Pywick requires **pytorch >= 1.4**
`pip install pywick`
or specific version from git:
`pip install git+https://github.com/achaiah/pywick.git@v0.6.5`
## ModuleTrainer
The `ModuleTrainer` class provides a high-level training interface which abstracts away the training loop while providing callbacks, constraints, initializers, regularizers,
and more.
See the `train_classifier.py` example for a pretty complete configuration example. To get up and running with your own data quickly simply edit the `configs/train_classifier.yaml` file with your desired parameters and dataset location(s).
Note: <i>Dataset needs to be organized for classification where each directory name is the name of a class and contains all images pertaining to that class</i>
PyWick provides a wide range of <b>callbacks</b>, generally mimicking the interface found in `Keras`:
- `CSVLogger` - Logs epoch-level metrics to a CSV file
- [`CyclicLRScheduler`](https://github.com/bckenstler/CLR) - Cycles through min-max learning rate
- `EarlyStopping` - Provides ability to stop training early based on supplied criteria
- `History` - Keeps history of metrics etc. during the learning process
- `LambdaCallback` - Allows you to implement your own callbacks on the fly
- `LRScheduler` - Simple learning rate scheduler based on function or supplied schedule
- `ModelCheckpoint` - Comprehensive model saver
- `ReduceLROnPlateau` - Reduces learning rate (LR) when a plateau has been reached
- `SimpleModelCheckpoint` - Simple model saver
- Additionally, a `TensorboardLogger` is incredibly easy to implement via tensorboardX (now part of pytorch 1.1 release!)
```python
from pywick.callbacks import EarlyStopping
callbacks = [EarlyStopping(monitor='val_loss', patience=5)]
trainer.set_callbacks(callbacks)
```
PyWick also provides <b>regularizers</b>:
- `L1Regularizer`
- `L2Regularizer`
- `L1L2Regularizer`
and <b>constraints</b>:
- `UnitNorm`
- `MaxNorm`
- `NonNeg`
Both regularizers and constraints can be selectively applied on layers using regular expressions and the `module_filter`
argument. Constraints can be explicit (hard) constraints applied at an arbitrary batch or
epoch frequency, or they can be implicit (soft) constraints similar to regularizers
where the constraint deviation is added as a penalty to the total model loss.
```python
from pywick.constraints import MaxNorm, NonNeg
from pywick.regularizers import L1Regularizer
# hard constraint applied every 5 batches
hard_constraint = MaxNorm(value=2., frequency=5, unit='batch', module_filter='*fc*')
# implicit constraint added as a penalty term to model loss
soft_constraint = NonNeg(lagrangian=True, scale=1e-3, module_filter='*fc*')
constraints = [hard_constraint, soft_constraint]
trainer.set_constraints(constraints)
regularizers = [L1Regularizer(scale=1e-4, module_filter='*conv*')]
trainer.set_regularizers(regularizers)
```
You can also fit directly on a `torch.utils.data.DataLoader` and can have
a validation set as well :
```python
from pywick import TensorDataset
from torch.utils.data import DataLoader
train_dataset = TensorDataset(x_train, y_train)
train_loader = DataLoader(train_dataset, batch_size=32)
val_dataset = TensorDataset(x_val, y_val)
val_loader = DataLoader(val_dataset, batch_size=32)
trainer.fit_loader(loader, val_loader=val_loader, num_epoch=100)
```
## Extensive Library of Image Classification Models (most are pretrained!)
- All standard models from Pytorch:
- [**Densenet**](https://arxiv.org/abs/1608.06993)
- [**Inception v3**](https://www.cv-foundation.org/openaccess/content_cvpr_2016/papers/Szegedy_Rethinking_the_Inception_CVPR_2016_paper.pdf)
- [**MobileNet v2**](https://arxiv.org/abs/1801.04381)
- [**ResNet**](https://arxiv.org/abs/1512.03385)
- [**ShuffleNet v2**](https://arxiv.org/abs/1807.11164)
- [**SqueezeNet**](https://arxiv.org/abs/1602.07360)
- [**VGG**](https://arxiv.org/abs/1409.1556)
- [**BatchNorm Inception**](https://arxiv.org/abs/1502.03167)
- [**Deep High-Resolution Representation Learning for Human Pose Estimation**](https://arxiv.org/abs/1902.09212v1)
- [**Deep Layer Aggregation**](https://arxiv.org/abs/1707.06484)
- [**Dual Path Networks**](https://arxiv.org/abs/1707.01629)
- [**EfficientNet variants (b0-b8, el, em, es, lite1-lite4, pruned, AP/NS)**](https://arxiv.org/abs/1905.11946)
- [**ECA-Net: Efficient Channel Attention for Deep Convolutional Neural Networks**](https://arxiv.org/abs/1910.03151v4)
- [**FBResnet**](https://github.com/facebook/fb.resnet.torch)
- [**FBNet-C**](https://arxiv.org/abs/1812.03443)
- [**Inception v4**](http://arxiv.org/abs/1602.07261)
- [**InceptionResnet v2**](https://arxiv.org/abs/1602.07261)
- [**Mixnet variants (l, m, s, xl, xxl)**](https://arxiv.org/abs/1907.09595)
- [**MnasNet**](https://arxiv.org/abs/1807.11626)
- [**MobileNet V3**](https://arxiv.org/abs/1905.02244)
- [**NasNet variants (mnas, pnas, mobile)**](https://arxiv.org/abs/1707.07012)
- [**PNASNet**](https://arxiv.org/abs/1712.00559)
- [**Polynet**](https://arxiv.org/abs/1611.05725)
- [**Pyramid Resnet**](https://arxiv.org/abs/1610.02915)
- [**RegNet - Designing Network Design Spaces**](https://arxiv.org/abs/2003.13678)
- **[Resnet variants (gluon, res2net, se, ssl, tv, wide)](https://arxiv.org/abs/1512.03385)**
- [**ResNeSt: Split-Attention Networks**](https://arxiv.org/abs/2004.08955)
- [**ResNext variants (ig, se, ssl, swsl, tv)**](https://arxiv.org/abs/1611.05431)
- [**SE Net variants (gluon, resnet, resnext, inception)**](https://arxiv.org/pdf/1709.01507.pdf)
- [**SelecSLS Convolutional Net**](https://github.com/mehtadushy/SelecSLS-Pytorch)
- [**Selective Kernel Networks**](https://arxiv.org/abs/1903.06586)
- [**Semi-Supervised and Semi-Weakly Supervised ImageNet Models**](https://github.com/facebookresearch/semi-supervised-ImageNet1K-models)
- [**Single-Pass NAS Net**](https://arxiv.org/abs/1904.02877)
- [**TResNet: High Performance GPU-Dedicated Architecture**](https://arxiv.org/abs/2003.13630)
- [**Wide Resnet**](https://arxiv.org/abs/1605.07146)
- [**XCeption**](https://arxiv.org/pdf/1610.02357.pdf)
- All the newest classification models (200+) from [rwightman's repo](https://github.com/rwightman/pytorch-image-models) ECA-NFNet, GERNet, RegNet, SKResnext, SWIN-Transformer, VIT etc.)
## Image Segmentation Models
- **BiSeNet** ([Bilateral Segmentation Network for Real-time Semantic Segmentation](https://arxiv.org/abs/1808.00897))
- **DANet** ([Dual Attention Network for Scene Segmentation](https://arxiv.org/abs/1809.02983))
- **Deeplab v2** ([DeepLab: Semantic Image Segmentation with Deep Convolutional Nets, Atrous Convolution, and Fully Connected CRFs](https://arxiv.org/abs/1606.00915))
- **Deeplab v3** ([Rethinking Atrous Convolution for Semantic Image Segmentation](https://arxiv.org/abs/1706.05587))
- **DenseASPP** ([DenseASPP for Semantic Segmentation in Street Scenes](http://openaccess.thecvf.com/content_cvpr_2018/papers/Yang_DenseASPP_for_Semantic_CVPR_2018_paper.pdf))
- **DRNNet** ([Dilated Residual Networks](http://openaccess.thecvf.com/content_cvpr_2017/papers/Yu_Dilated_Residual_Networks_CVPR_2017_paper.pdf))
- **DUC, HDC** ([understanding convolution for semantic segmentation](https://arxiv.org/abs/1702.08502))
- **DUNet** ([Decoders Matter for Semantic Segmentation](https://arxiv.org/abs/1903.02120))
- **ENet** ([ENet: A Deep Neural Network Architecture for Real-Time Semantic Segmentation](https://arxiv.org/abs/1606.02147))
- **Vanilla FCN:** FCN32, FCN16, FCN8, in the versions of VGG, ResNet
and OptDenseNet respectively ([Fully convolutional networks for semantic segmentation](http://www.cv-foundation.org/openaccess/content_cvpr_2015/papers/Long_Fully_Convolutional_Networks_2015_CVPR_paper.pdf))
- **FRRN** ([Full Resolution Residual Networks for Semantic Segmentation in Street Scenes](https://arxiv.org/abs/1611.08323))
- **FusionNet** ([FusionNet in Tensorflow by Hyungjoo Andrew Cho](https://github.com/NySunShine/fusion-net))
- **GALDNet**
- **GCN** ([Large Kernel Matters](https://arxiv.org/pdf/1703.02719))
- **LinkNet** ([Link-Net](https://codeac29.github.io/projects/linknet/))
- **OCNet** ([Object Context Network for Scene Parsing](https://arxiv.org/abs/1809.00916))
- **PSPNet** ([Pyramid scene parsing network](https://arxiv.org/abs/1612.01105))
- **RefineNet** ([RefineNet](https://arxiv.org/abs/1611.06612))
- **SegNet** ([Segnet: A deep convolutional encoder-decoder architecture for image segmentation](https://arxiv.org/pdf/1511.00561))
- **Tiramisu** ([The One Hundred Layers Tiramisu: Fully Convolutional DenseNets for Semantic Segmentation](https://arxiv.org/abs/1611.09326))
- **U-Net** ([U-net: Convolutional networks for biomedical image segmentation](https://arxiv.org/abs/1505.04597))
- Additional variations of many of the above
###### To load one of these models:
[Read the docs](https://pywick.readthedocs.io/en/latest/api/pywick.models.html)
for useful details! Then dive in:
```python
# use the `get_model` utility
from pywick.models.model_utils import get_model, ModelType
model = get_model(model_type=ModelType.CLASSIFICATION, model_name='resnet18', num_classes=1000, pretrained=True)
```
For a complete list of models (including many experimental ones) you can call the `get_supported_models` method e.g.
`pywick.models.model_utils.get_supported_models(ModelType.SEGMENTATION)`
## Data Augmentation and Datasets
The PyWick package provides wide variety of good data augmentation and transformation
tools which can be applied during data loading. The package also provides the flexible
`TensorDataset`, `FolderDataset` and `MultiFolderDataset` classes to handle most dataset needs.
### Torch Transforms
##### These transforms work directly on torch tensors
- `AddChannel`
- `ChannelsFirst`
- `ChannelsLast`
- `Compose`
- `ExpandAxis`
- `Pad`
- `PadNumpy`
- `RandomChoiceCompose`
- `RandomCrop`
- `RandomFlip`
- `RandomOrder`
- `RangeNormalize`
- `Slice2D`
- `SpecialCrop`
- `StdNormalize`
- `ToFile`
- `ToNumpyType`
- `ToTensor`
- `Transpose`
- `TypeCast`
##### Additionally, we provide image-specific manipulations directly on tensors:
- `Brightness`
- `Contrast`
- `Gamma`
- `Grayscale`
- `RandomBrightness`
- `RandomChoiceBrightness`
- `RandomChoiceContrast`
- `RandomChoiceGamma`
- `RandomChoiceSaturation`
- `RandomContrast`
- `RandomGamma`
- `RandomGrayscale`
- `RandomSaturation`
- `Saturation`
##### Affine Transforms (perform affine or affine-like transforms on torch tensors)
- `RandomAffine`
- `RandomChoiceRotate`
- `RandomChoiceShear`
- `RandomChoiceTranslate`
- `RandomChoiceZoom`
- `RandomRotate`
- `RandomShear`
- `RandomSquareZoom`
- `RandomTranslate`
- `RandomZoom`
- `Rotate`
- `Shear`
- `Translate`
- `Zoom`
We also provide a class for stringing multiple affine transformations together so that only one interpolation takes place:
- `Affine`
- `AffineCompose`
##### Blur and Scramble transforms (for tensors)
- `Blur`
- `RandomChoiceBlur`
- `RandomChoiceScramble`
- `Scramble`
### Datasets and Sampling
We provide the following datasets which provide general structure and iterators for sampling from and using transforms on in-memory or out-of-memory data. In particular,
the [FolderDataset](pywick/datasets/FolderDataset.py) has been designed to fit most of your dataset needs. It has extensive options for data filtering and manipulation.
It supports loading images for classification, segmentation and even arbitrary source/target mapping. Take a good look at its documentation for more info.
- `ClonedDataset`
- `CSVDataset`
- `FolderDataset`
- `MultiFolderDataset`
- `TensorDataset`
- `tnt.BatchDataset`
- `tnt.ConcatDataset`
- `tnt.ListDataset`
- `tnt.MultiPartitionDataset`
- `tnt.ResampleDataset`
- `tnt.ShuffleDataset`
- `tnt.TensorDataset`
- `tnt.TransformDataset`
### Imbalanced Datasets
In many scenarios it is important to ensure that your traing set is properly balanced,
however, it may not be practical in real life to obtain such a perfect dataset. In these cases
you can use the `ImbalancedDatasetSampler` as a drop-in replacement for the basic sampler provided
by the DataLoader. More information can be found [here](https://github.com/ufoym/imbalanced-dataset-sampler)
```python
from pywick.samplers import ImbalancedDatasetSampler
train_loader = torch.utils.data.DataLoader(train_dataset,
sampler=ImbalancedDatasetSampler(train_dataset),
batch_size=args.batch_size, **kwargs)
```
## Utility Functions
PyWick provides a few utility functions not commonly found:
### Tensor Functions
- `th_iterproduct` (mimics itertools.product)
- `th_gather_nd` (N-dimensional version of torch.gather)
- `th_random_choice` (mimics np.random.choice)
- `th_pearsonr` (mimics scipy.stats.pearsonr)
- `th_corrcoef` (mimics np.corrcoef)
- `th_affine2d` and `th_affine3d` (affine transforms on torch.Tensors)
## Acknowledgements and References
We stand on the shoulders of (github?) giants and couldn't have done
this without the rich github ecosystem and community. This framework is
based in part on the excellent
[Torchsample](https://github.com/ncullen93/torchsample) framework
originally published by @ncullen93. Additionally, many models have been
gently borrowed/modified from @Cadene pretrained models
[repo](https://github.com/Cadene/pretrained-models.pytorch) as well as @Tramac segmentation [repo](https://github.com/Tramac/awesome-semantic-segmentation-pytorch).
##### Thank you to the following people and the projects they maintain:
- @ncullen93
- @cadene
- @deallynomore
- @recastrodiaz
- @zijundeng
- @Tramac
- And many others! (attributions listed in the codebase as they occur)
##### Thank you to the following projects from which we gently borrowed code and models
- [PyTorchNet](https://github.com/pytorch/tnt)
- [pretrained-models.pytorch](https://github.com/Cadene/pretrained-models.pytorch)
- [DeepLab_pytorch](https://github.com/doiken23/DeepLab_pytorch)
- [Pytorch for Semantic Segmentation](https://github.com/zijundeng/pytorch-semantic-segmentation)
- [Binseg Pytorch](https://github.com/saeedizadi/binseg_pytoch)
- [awesome-semantic-segmentation-pytorch](https://github.com/Tramac/awesome-semantic-segmentation-pytorch)
- And many others! (attributions listed in the codebase as they occur)
| *Thangs are broken matey! Arrr!!!* |
|-----------------------|
| We're working on this project as time permits so you might discover bugs here and there. Feel free to report them, or better yet, to submit a pull request! |
%prep
%autosetup -n pywick-0.6.5
%build
%py3_build
%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .
%files -n python3-pywick -f filelist.lst
%dir %{python3_sitelib}/*
%files help -f doclist.lst
%{_docdir}/*
%changelog
* Fri May 05 2023 Python_Bot <Python_Bot@openeuler.org> - 0.6.5-1
- Package Spec generated
|