Myosotis-Researches 0.1.7__tar.gz → 0.1.8__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.
Files changed (65) hide show
  1. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8/Myosotis_Researches.egg-info}/PKG-INFO +1 -1
  2. {myosotis_researches-0.1.7/Myosotis_Researches.egg-info → myosotis_researches-0.1.8}/PKG-INFO +1 -1
  3. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/utils/__init__.py +2 -1
  4. myosotis_researches-0.1.8/myosotis_researches/CcGAN/utils/train.py +156 -0
  5. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/setup.py +1 -1
  6. myosotis_researches-0.1.7/myosotis_researches/CcGAN/utils/train.py +0 -65
  7. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/LICENSE +0 -0
  8. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/Myosotis_Researches.egg-info/SOURCES.txt +0 -0
  9. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/Myosotis_Researches.egg-info/dependency_links.txt +0 -0
  10. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/Myosotis_Researches.egg-info/top_level.txt +0 -0
  11. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/README.md +0 -0
  12. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/__init__.py +0 -0
  13. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/internal/__init__.py +0 -0
  14. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/internal/install_datasets.py +0 -0
  15. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/internal/show_datasets.py +0 -0
  16. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/internal/uninstall_datasets.py +0 -0
  17. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/models_128/CcGAN_SAGAN.py +0 -0
  18. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/models_128/ResNet_class_eval.py +0 -0
  19. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/models_128/ResNet_embed.py +0 -0
  20. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/models_128/ResNet_regre_eval.py +0 -0
  21. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/models_128/__init__.py +0 -0
  22. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/models_128/autoencoder.py +0 -0
  23. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/models_128/cGAN_SAGAN.py +0 -0
  24. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/models_128/cGAN_concat_SAGAN.py +0 -0
  25. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/models_256/CcGAN_SAGAN.py +0 -0
  26. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/models_256/ResNet_class_eval.py +0 -0
  27. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/models_256/ResNet_embed.py +0 -0
  28. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/models_256/ResNet_regre_eval.py +0 -0
  29. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/models_256/__init__.py +0 -0
  30. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/models_256/autoencoder.py +0 -0
  31. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/models_256/cGAN_SAGAN.py +0 -0
  32. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/models_256/cGAN_concat_SAGAN.py +0 -0
  33. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/train_128/DiffAugment_pytorch.py +0 -0
  34. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/train_128/__init__.py +0 -0
  35. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/train_128/eval_metrics.py +0 -0
  36. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/train_128/opts.py +0 -0
  37. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/train_128/pretrain_AE.py +0 -0
  38. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/train_128/pretrain_CNN_class.py +0 -0
  39. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/train_128/pretrain_CNN_regre.py +0 -0
  40. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/train_128/train_ccgan.py +0 -0
  41. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/train_128/train_cgan.py +0 -0
  42. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/train_128/train_cgan_concat.py +0 -0
  43. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/train_128/train_net_for_label_embed.py +0 -0
  44. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/train_128/utils.py +0 -0
  45. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/train_128_output_10/DiffAugment_pytorch.py +0 -0
  46. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/train_128_output_10/__init__.py +0 -0
  47. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/train_128_output_10/eval_metrics.py +0 -0
  48. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/train_128_output_10/opts.py +0 -0
  49. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/train_128_output_10/pretrain_AE.py +0 -0
  50. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/train_128_output_10/pretrain_CNN_class.py +0 -0
  51. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/train_128_output_10/pretrain_CNN_regre.py +0 -0
  52. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/train_128_output_10/train_ccgan.py +0 -0
  53. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/train_128_output_10/train_cgan.py +0 -0
  54. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/train_128_output_10/train_cgan_concat.py +0 -0
  55. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/train_128_output_10/train_net_for_label_embed.py +0 -0
  56. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/train_128_output_10/utils.py +0 -0
  57. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/utils/IMGs_dataset.py +0 -0
  58. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/utils/SimpleProgressBar.py +0 -0
  59. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/utils/concat_image.py +0 -0
  60. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/utils/make_h5.py +0 -0
  61. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/utils/opts.py +0 -0
  62. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/CcGAN/utils/print_hdf5.py +0 -0
  63. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/myosotis_researches/__init__.py +0 -0
  64. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/pyproject.toml +0 -0
  65. {myosotis_researches-0.1.7 → myosotis_researches-0.1.8}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: Myosotis-Researches
3
- Version: 0.1.7
3
+ Version: 0.1.8
4
4
  Summary: A repository for storing my progress of researches.
5
5
  Home-page: https://github.com/Zeyu-Xie/Myosotis-Researches
6
6
  Author: Zeyu Xie
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: Myosotis-Researches
3
- Version: 0.1.7
3
+ Version: 0.1.8
4
4
  Summary: A repository for storing my progress of researches.
5
5
  Home-page: https://github.com/Zeyu-Xie/Myosotis-Researches
6
6
  Author: Zeyu Xie
@@ -3,7 +3,7 @@ from .concat_image import concat_image
3
3
  from .make_h5 import make_h5
4
4
  from .SimpleProgressBar import SimpleProgressBar
5
5
  from .IMGs_dataset import IMGs_dataset
6
- from .train import PlotLoss, compute_entropy, predict_class_labels
6
+ from .train import PlotLoss, compute_entropy, predict_class_labels, DiffAugment
7
7
  from .opts import parse_opts
8
8
 
9
9
  __all__ = [
@@ -15,5 +15,6 @@ __all__ = [
15
15
  "PlotLoss",
16
16
  "compute_entropy",
17
17
  "predict_class_labels",
18
+ "DiffAugment",
18
19
  "parse_opts"
19
20
  ]
@@ -0,0 +1,156 @@
1
+ import matplotlib as mpl
2
+ import matplotlib.pyplot as plt
3
+ import numpy as np
4
+ import torch
5
+ import torch.nn.functional as F
6
+
7
+
8
+ def PlotLoss(loss, filename):
9
+ x_axis = np.arange(start=1, stop=len(loss) + 1)
10
+ plt.switch_backend("agg")
11
+ mpl.style.use("seaborn")
12
+ fig = plt.figure()
13
+ ax = plt.subplot(111)
14
+ ax.plot(x_axis, np.array(loss))
15
+ plt.xlabel("epoch")
16
+ plt.ylabel("training loss")
17
+ plt.legend()
18
+ # ax.legend(loc='upper center', bbox_to_anchor=(0.5, 1.15), shadow=True, ncol=3)
19
+ # plt.title('Training Loss')
20
+ plt.savefig(filename)
21
+
22
+
23
+ # compute entropy of class labels; labels is a numpy array
24
+ def compute_entropy(labels, base=None):
25
+ value, counts = np.unique(labels, return_counts=True)
26
+ norm_counts = counts / counts.sum()
27
+ base = np.e if base is None else base
28
+ return -(norm_counts * np.log(norm_counts) / np.log(base)).sum()
29
+
30
+
31
+ def predict_class_labels(net, images, batch_size=500, verbose=False, num_workers=0):
32
+ net = net.cuda()
33
+ net.eval()
34
+
35
+ n = len(images)
36
+ if batch_size > n:
37
+ batch_size = n
38
+ dataset_pred = IMGs_dataset(images, normalize=False)
39
+ dataloader_pred = torch.utils.data.DataLoader(
40
+ dataset_pred, batch_size=batch_size, shuffle=False, num_workers=num_workers
41
+ )
42
+
43
+ class_labels_pred = np.zeros(n + batch_size)
44
+ with torch.no_grad():
45
+ nimgs_got = 0
46
+ if verbose:
47
+ pb = SimpleProgressBar()
48
+ for batch_idx, batch_images in enumerate(dataloader_pred):
49
+ batch_images = batch_images.type(torch.float).cuda()
50
+ batch_size_curr = len(batch_images)
51
+
52
+ outputs, _ = net(batch_images)
53
+ _, batch_class_labels_pred = torch.max(outputs.data, 1)
54
+ class_labels_pred[nimgs_got : (nimgs_got + batch_size_curr)] = (
55
+ batch_class_labels_pred.detach().cpu().numpy().reshape(-1)
56
+ )
57
+
58
+ nimgs_got += batch_size_curr
59
+ if verbose:
60
+ pb.update((float(nimgs_got) / n) * 100)
61
+ # end for batch_idx
62
+ class_labels_pred = class_labels_pred[0:n]
63
+ return class_labels_pred
64
+
65
+
66
+ def DiffAugment(x, policy="", channels_first=True):
67
+ if policy:
68
+ if not channels_first:
69
+ x = x.permute(0, 3, 1, 2)
70
+ for p in policy.split(","):
71
+ for f in AUGMENT_FNS[p]:
72
+ x = f(x)
73
+ if not channels_first:
74
+ x = x.permute(0, 2, 3, 1)
75
+ x = x.contiguous()
76
+ return x
77
+
78
+
79
+ def rand_brightness(x):
80
+ x = x + (torch.rand(x.size(0), 1, 1, 1, dtype=x.dtype, device=x.device) - 0.5)
81
+ return x
82
+
83
+
84
+ def rand_saturation(x):
85
+ x_mean = x.mean(dim=1, keepdim=True)
86
+ x = (x - x_mean) * (
87
+ torch.rand(x.size(0), 1, 1, 1, dtype=x.dtype, device=x.device) * 2
88
+ ) + x_mean
89
+ return x
90
+
91
+
92
+ def rand_contrast(x):
93
+ x_mean = x.mean(dim=[1, 2, 3], keepdim=True)
94
+ x = (x - x_mean) * (
95
+ torch.rand(x.size(0), 1, 1, 1, dtype=x.dtype, device=x.device) + 0.5
96
+ ) + x_mean
97
+ return x
98
+
99
+
100
+ def rand_translation(x, ratio=0.125):
101
+ shift_x, shift_y = int(x.size(2) * ratio + 0.5), int(x.size(3) * ratio + 0.5)
102
+ translation_x = torch.randint(
103
+ -shift_x, shift_x + 1, size=[x.size(0), 1, 1], device=x.device
104
+ )
105
+ translation_y = torch.randint(
106
+ -shift_y, shift_y + 1, size=[x.size(0), 1, 1], device=x.device
107
+ )
108
+ grid_batch, grid_x, grid_y = torch.meshgrid(
109
+ torch.arange(x.size(0), dtype=torch.long, device=x.device),
110
+ torch.arange(x.size(2), dtype=torch.long, device=x.device),
111
+ torch.arange(x.size(3), dtype=torch.long, device=x.device),
112
+ )
113
+ grid_x = torch.clamp(grid_x + translation_x + 1, 0, x.size(2) + 1)
114
+ grid_y = torch.clamp(grid_y + translation_y + 1, 0, x.size(3) + 1)
115
+ x_pad = F.pad(x, [1, 1, 1, 1, 0, 0, 0, 0])
116
+ x = (
117
+ x_pad.permute(0, 2, 3, 1)
118
+ .contiguous()[grid_batch, grid_x, grid_y]
119
+ .permute(0, 3, 1, 2)
120
+ )
121
+ return x
122
+
123
+
124
+ def rand_cutout(x, ratio=0.5):
125
+ cutout_size = int(x.size(2) * ratio + 0.5), int(x.size(3) * ratio + 0.5)
126
+ offset_x = torch.randint(
127
+ 0, x.size(2) + (1 - cutout_size[0] % 2), size=[x.size(0), 1, 1], device=x.device
128
+ )
129
+ offset_y = torch.randint(
130
+ 0, x.size(3) + (1 - cutout_size[1] % 2), size=[x.size(0), 1, 1], device=x.device
131
+ )
132
+ grid_batch, grid_x, grid_y = torch.meshgrid(
133
+ torch.arange(x.size(0), dtype=torch.long, device=x.device),
134
+ torch.arange(cutout_size[0], dtype=torch.long, device=x.device),
135
+ torch.arange(cutout_size[1], dtype=torch.long, device=x.device),
136
+ )
137
+ grid_x = torch.clamp(
138
+ grid_x + offset_x - cutout_size[0] // 2, min=0, max=x.size(2) - 1
139
+ )
140
+ grid_y = torch.clamp(
141
+ grid_y + offset_y - cutout_size[1] // 2, min=0, max=x.size(3) - 1
142
+ )
143
+ mask = torch.ones(x.size(0), x.size(2), x.size(3), dtype=x.dtype, device=x.device)
144
+ mask[grid_batch, grid_x, grid_y] = 0
145
+ x = x * mask.unsqueeze(1)
146
+ return x
147
+
148
+
149
+ AUGMENT_FNS = {
150
+ "color": [rand_brightness, rand_saturation, rand_contrast],
151
+ "translation": [rand_translation],
152
+ "cutout": [rand_cutout],
153
+ }
154
+
155
+
156
+ __all__ = ["PlotLoss", "compute_entropy", "predict_class_labels", "DiffAugment"]
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="Myosotis-Researches",
5
- version="0.1.7",
5
+ version="0.1.8",
6
6
  description="A repository for storing my progress of researches.",
7
7
  long_description=open("README.md").read(),
8
8
  long_description_content_type="text/markdown",
@@ -1,65 +0,0 @@
1
- import numpy as np
2
- import torch
3
- import matplotlib.pyplot as plt
4
- import matplotlib as mpl
5
-
6
-
7
- def PlotLoss(loss, filename):
8
- x_axis = np.arange(start=1, stop=len(loss) + 1)
9
- plt.switch_backend("agg")
10
- mpl.style.use("seaborn")
11
- fig = plt.figure()
12
- ax = plt.subplot(111)
13
- ax.plot(x_axis, np.array(loss))
14
- plt.xlabel("epoch")
15
- plt.ylabel("training loss")
16
- plt.legend()
17
- # ax.legend(loc='upper center', bbox_to_anchor=(0.5, 1.15), shadow=True, ncol=3)
18
- # plt.title('Training Loss')
19
- plt.savefig(filename)
20
-
21
-
22
- # compute entropy of class labels; labels is a numpy array
23
- def compute_entropy(labels, base=None):
24
- value, counts = np.unique(labels, return_counts=True)
25
- norm_counts = counts / counts.sum()
26
- base = np.e if base is None else base
27
- return -(norm_counts * np.log(norm_counts) / np.log(base)).sum()
28
-
29
-
30
- def predict_class_labels(net, images, batch_size=500, verbose=False, num_workers=0):
31
- net = net.cuda()
32
- net.eval()
33
-
34
- n = len(images)
35
- if batch_size > n:
36
- batch_size = n
37
- dataset_pred = IMGs_dataset(images, normalize=False)
38
- dataloader_pred = torch.utils.data.DataLoader(
39
- dataset_pred, batch_size=batch_size, shuffle=False, num_workers=num_workers
40
- )
41
-
42
- class_labels_pred = np.zeros(n + batch_size)
43
- with torch.no_grad():
44
- nimgs_got = 0
45
- if verbose:
46
- pb = SimpleProgressBar()
47
- for batch_idx, batch_images in enumerate(dataloader_pred):
48
- batch_images = batch_images.type(torch.float).cuda()
49
- batch_size_curr = len(batch_images)
50
-
51
- outputs, _ = net(batch_images)
52
- _, batch_class_labels_pred = torch.max(outputs.data, 1)
53
- class_labels_pred[nimgs_got : (nimgs_got + batch_size_curr)] = (
54
- batch_class_labels_pred.detach().cpu().numpy().reshape(-1)
55
- )
56
-
57
- nimgs_got += batch_size_curr
58
- if verbose:
59
- pb.update((float(nimgs_got) / n) * 100)
60
- # end for batch_idx
61
- class_labels_pred = class_labels_pred[0:n]
62
- return class_labels_pred
63
-
64
-
65
- __all__ = ["PlotLoss", "compute_entropy", "predict_class_labels"]