tensorneko 0.3.4__tar.gz → 0.3.5__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.
- {tensorneko-0.3.4/src/tensorneko.egg-info → tensorneko-0.3.5}/PKG-INFO +2 -2
- {tensorneko-0.3.4 → tensorneko-0.3.5}/README.md +1 -1
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/arch/__init__.py +3 -1
- tensorneko-0.3.5/src/tensorneko/arch/binary_classifier.py +54 -0
- tensorneko-0.3.5/src/tensorneko/dataset/__init__.py +11 -0
- tensorneko-0.3.5/src/tensorneko/dataset/list_dataset.py +19 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/dataset/round_robin_dataset.py +1 -1
- tensorneko-0.3.5/src/tensorneko/dataset/sampler/__init__.py +5 -0
- tensorneko-0.3.5/src/tensorneko/dataset/sampler/sequential_iter_sampler.py +26 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/evaluation/__init__.py +2 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/evaluation/fid.py +39 -3
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/evaluation/iou.py +1 -1
- tensorneko-0.3.5/src/tensorneko/evaluation/secs.py +58 -0
- tensorneko-0.3.5/src/tensorneko/version.txt +1 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5/src/tensorneko.egg-info}/PKG-INFO +2 -2
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko.egg-info/SOURCES.txt +5 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko.egg-info/requires.txt +2 -2
- tensorneko-0.3.4/src/tensorneko/dataset/__init__.py +0 -5
- tensorneko-0.3.4/src/tensorneko/version.txt +0 -1
- {tensorneko-0.3.4 → tensorneko-0.3.5}/LICENSE +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/setup.cfg +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/setup.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/__init__.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/arch/auto_encoder.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/arch/gan.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/arch/vqvae.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/arch/wgan.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/backend/__init__.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/callback/__init__.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/callback/display_metrics_callback.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/callback/earlystop_lr.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/callback/epoch_num_logger.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/callback/epoch_time_logger.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/callback/gpu_stats_logger.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/callback/lr_logger.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/callback/nil_callback.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/callback/system_stats_logger.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/dataset/nested_dataset.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/debug/__init__.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/evaluation/enum.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/evaluation/psnr.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/evaluation/ssim.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/io/__init__.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/io/mesh/__init__.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/io/mesh/mesh_reader.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/io/mesh/mesh_writer.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/io/reader.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/io/writer.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/layer/__init__.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/layer/aggregation.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/layer/attention.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/layer/concatenate.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/layer/conv.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/layer/linear.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/layer/log.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/layer/masked_conv2d.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/layer/noise.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/layer/patching.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/layer/positional_embedding.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/layer/reshape.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/layer/stack.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/layer/vector_quantizer.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/module/__init__.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/module/dense.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/module/gated_conv.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/module/inception.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/module/mlp.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/module/residual.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/module/transformer.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/neko_model.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/neko_module.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/neko_trainer.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/notebook/__init__.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/optim/__init__.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/optim/lr_scheduler/__init__.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/preprocess/__init__.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/preprocess/crop.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/preprocess/enum.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/preprocess/face_detector/__init__.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/preprocess/pad.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/preprocess/resize.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/util/__init__.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/util/configuration.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/util/dispatched_misc.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/util/misc.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/util/reproducibility.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/util/string_getter.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/util/type.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/visualization/__init__.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/visualization/image_browser/__init__.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/visualization/log_graph.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/visualization/matplotlib.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/visualization/watcher/__init__.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko.egg-info/dependency_links.txt +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko.egg-info/top_level.txt +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/test/test_library_info.py +0 -0
- {tensorneko-0.3.4 → tensorneko-0.3.5}/test/test_version.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: tensorneko
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.5
|
|
4
4
|
Summary: Tensor Neural Engine Kompanion. An util library based on PyTorch and PyTorch Lightning.
|
|
5
5
|
Home-page: https://github.com/ControlNet/tensorneko
|
|
6
6
|
Author: ControlNet
|
|
@@ -38,7 +38,7 @@ License-File: LICENSE
|
|
|
38
38
|
<div align="center">
|
|
39
39
|
<a href="https://www.python.org/"><img src="https://img.shields.io/pypi/pyversions/tensorneko?style=flat-square"></a>
|
|
40
40
|
<a href="https://pytorch.org/"><img src="https://img.shields.io/badge/PyTorch-%3E%3D1.9.0-EE4C2C?style=flat-square&logo=pytorch"></a>
|
|
41
|
-
<a href="https://www.pytorchlightning.ai/"><img src="https://img.shields.io/badge/Lightning-2.0.*-792EE5?style=flat-square&logo=lightning"></a>
|
|
41
|
+
<a href="https://www.pytorchlightning.ai/"><img src="https://img.shields.io/badge/Lightning-2.0.*/2.1.*-792EE5?style=flat-square&logo=lightning"></a>
|
|
42
42
|
</div>
|
|
43
43
|
|
|
44
44
|
<div align="center">
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
<div align="center">
|
|
13
13
|
<a href="https://www.python.org/"><img src="https://img.shields.io/pypi/pyversions/tensorneko?style=flat-square"></a>
|
|
14
14
|
<a href="https://pytorch.org/"><img src="https://img.shields.io/badge/PyTorch-%3E%3D1.9.0-EE4C2C?style=flat-square&logo=pytorch"></a>
|
|
15
|
-
<a href="https://www.pytorchlightning.ai/"><img src="https://img.shields.io/badge/Lightning-2.0.*-792EE5?style=flat-square&logo=lightning"></a>
|
|
15
|
+
<a href="https://www.pytorchlightning.ai/"><img src="https://img.shields.io/badge/Lightning-2.0.*/2.1.*-792EE5?style=flat-square&logo=lightning"></a>
|
|
16
16
|
</div>
|
|
17
17
|
|
|
18
18
|
<div align="center">
|
|
@@ -2,10 +2,12 @@ from .gan import GAN
|
|
|
2
2
|
from .vqvae import VQVAE
|
|
3
3
|
from .wgan import WGAN
|
|
4
4
|
from .auto_encoder import AutoEncoder
|
|
5
|
+
from .binary_classifier import BinaryClassifier
|
|
5
6
|
|
|
6
7
|
__all__ = [
|
|
7
8
|
"GAN",
|
|
8
9
|
"VQVAE",
|
|
9
10
|
"WGAN",
|
|
10
|
-
"AutoEncoder"
|
|
11
|
+
"AutoEncoder",
|
|
12
|
+
"BinaryClassifier",
|
|
11
13
|
]
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
from abc import ABC
|
|
2
|
+
from typing import Optional, Union, Sequence, Dict
|
|
3
|
+
|
|
4
|
+
from torch import Tensor
|
|
5
|
+
from torch.nn import BCEWithLogitsLoss
|
|
6
|
+
from torch.optim import Adam
|
|
7
|
+
from torchmetrics import Accuracy, F1Score, AUROC
|
|
8
|
+
|
|
9
|
+
from ..neko_model import NekoModel
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class BinaryClassifier(NekoModel, ABC):
|
|
13
|
+
|
|
14
|
+
def __init__(self, model=None, learning_rate: float = 1e-4, distributed: bool = False):
|
|
15
|
+
super().__init__()
|
|
16
|
+
self.save_hyperparameters()
|
|
17
|
+
self.model = model
|
|
18
|
+
self.learning_rate = learning_rate
|
|
19
|
+
self.distributed = distributed
|
|
20
|
+
self.loss_fn = BCEWithLogitsLoss()
|
|
21
|
+
self.acc_fn = Accuracy(task="binary")
|
|
22
|
+
self.f1_fn = F1Score(task="binary")
|
|
23
|
+
self.auc_fn = AUROC(task="binary")
|
|
24
|
+
|
|
25
|
+
@classmethod
|
|
26
|
+
def from_module(cls, model, learning_rate: float = 1e-4, distributed=False):
|
|
27
|
+
return cls(model, learning_rate, distributed)
|
|
28
|
+
|
|
29
|
+
def forward(self, x):
|
|
30
|
+
return self.model(x)
|
|
31
|
+
|
|
32
|
+
def step(self, batch: Optional[Union[Tensor, Sequence[Tensor]]]) -> Dict[str, Tensor]:
|
|
33
|
+
x, y = batch
|
|
34
|
+
y_hat = self(x).squeeze(1)
|
|
35
|
+
loss = self.loss_fn(y_hat, y)
|
|
36
|
+
prob = y_hat.sigmoid()
|
|
37
|
+
acc = self.acc_fn(prob, y)
|
|
38
|
+
f1 = self.f1_fn(prob, y)
|
|
39
|
+
auc = self.auc_fn(prob, y)
|
|
40
|
+
return {"loss": loss, "acc": acc, "f1": f1, "auc": auc}
|
|
41
|
+
|
|
42
|
+
def training_step(self, batch: Optional[Union[Tensor, Sequence[Tensor]]] = None, batch_idx: Optional[int] = None,
|
|
43
|
+
optimizer_idx: Optional[int] = None, hiddens: Optional[Tensor] = None
|
|
44
|
+
) -> Dict[str, Tensor]:
|
|
45
|
+
return self.step(batch)
|
|
46
|
+
|
|
47
|
+
def validation_step(self, batch: Optional[Union[Tensor, Sequence[Tensor]]] = None, batch_idx: Optional[int] = None,
|
|
48
|
+
dataloader_idx: Optional[int] = None
|
|
49
|
+
) -> Dict[str, Tensor]:
|
|
50
|
+
return self.step(batch)
|
|
51
|
+
|
|
52
|
+
def configure_optimizers(self):
|
|
53
|
+
optimizer = Adam(self.parameters(), lr=self.learning_rate)
|
|
54
|
+
return [optimizer]
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from typing import List
|
|
2
|
+
|
|
3
|
+
from torch.utils.data.dataset import Dataset, T_co
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class ListDataset(Dataset[T_co]):
|
|
7
|
+
"""
|
|
8
|
+
A dataset wrapping a list of data.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
def __init__(self, data: List[T_co]):
|
|
12
|
+
super().__init__()
|
|
13
|
+
self.data = data
|
|
14
|
+
|
|
15
|
+
def __getitem__(self, index: int) -> T_co:
|
|
16
|
+
return self.data[index]
|
|
17
|
+
|
|
18
|
+
def __len__(self):
|
|
19
|
+
return len(self.data)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from typing import Sized
|
|
2
|
+
|
|
3
|
+
from torch.utils.data.sampler import Sampler, T_co
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class SequentialIterSampler(Sampler[T_co]):
|
|
7
|
+
"""
|
|
8
|
+
Use to split the large scale data into small subsets for each epochs
|
|
9
|
+
For example, if the dataset size is 1M, and the num_samples = 1000, then each epoch will only use 1000 samples, and
|
|
10
|
+
the next epoch will use the next 1000 samples.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
def __init__(self, data_source: Sized, num_samples: int):
|
|
14
|
+
super().__init__(data_source)
|
|
15
|
+
self.data_source = data_source
|
|
16
|
+
self.num_samples = num_samples
|
|
17
|
+
self.total_size = len(data_source)
|
|
18
|
+
self.current_position = 0
|
|
19
|
+
|
|
20
|
+
def __iter__(self):
|
|
21
|
+
yield from map(lambda x: x % self.total_size,
|
|
22
|
+
range(self.current_position, self.current_position + self.num_samples))
|
|
23
|
+
self.current_position = (self.current_position + self.num_samples) % self.total_size
|
|
24
|
+
|
|
25
|
+
def __len__(self):
|
|
26
|
+
return self.num_samples
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from .iou import iou_1d, iou_2d
|
|
2
2
|
from .psnr import psnr_video, psnr_image
|
|
3
3
|
from .ssim import ssim_video, ssim_image
|
|
4
|
+
from .secs import secs
|
|
4
5
|
from .fid import FID
|
|
5
6
|
|
|
6
7
|
__all__ = [
|
|
@@ -10,5 +11,6 @@ __all__ = [
|
|
|
10
11
|
"psnr_image",
|
|
11
12
|
"ssim_video",
|
|
12
13
|
"ssim_image",
|
|
14
|
+
"secs",
|
|
13
15
|
"FID",
|
|
14
16
|
]
|
|
@@ -22,6 +22,34 @@ except ImportError:
|
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
class FID:
|
|
25
|
+
"""
|
|
26
|
+
Calculate Fréchet inception distance based on torchmetrics. Require library "torch-fidelity".
|
|
27
|
+
|
|
28
|
+
Args:
|
|
29
|
+
device (``str`` | :class:`~torch.device`, optional): Device to run the metric. Default: ``"cpu"``.
|
|
30
|
+
|
|
31
|
+
Example::
|
|
32
|
+
|
|
33
|
+
from tensorneko.evaluation import FID
|
|
34
|
+
fid = FID("cuda")
|
|
35
|
+
|
|
36
|
+
# add predicted and real images
|
|
37
|
+
fid.add_pred_image("path/to/pred/image1.png")
|
|
38
|
+
fid.add_pred_image("path/to/pred/image2.png")
|
|
39
|
+
fid.add_true_image("path/to/true/image1.png")
|
|
40
|
+
fid.add_true_image("path/to/true/image2.png")
|
|
41
|
+
|
|
42
|
+
# add predicted and real videos
|
|
43
|
+
fid.add_pred_video("path/to/pred/video1.mp4")
|
|
44
|
+
fid.add_pred_video("path/to/pred/video2.mp4")
|
|
45
|
+
fid.add_true_video("path/to/true/video1.mp4")
|
|
46
|
+
fid.add_true_video("path/to/true/video2.mp4")
|
|
47
|
+
|
|
48
|
+
# compute FID
|
|
49
|
+
fid_score = fid.compute(batch_size=128, num_workers=8, progress_bar=True)
|
|
50
|
+
print(fid_score)
|
|
51
|
+
|
|
52
|
+
"""
|
|
25
53
|
|
|
26
54
|
def __init__(self, device: Union[str, Device] = "cpu"):
|
|
27
55
|
self.device = torch.device(device)
|
|
@@ -56,14 +84,14 @@ class FID:
|
|
|
56
84
|
def cuda(self) -> FID:
|
|
57
85
|
return self.to("cuda")
|
|
58
86
|
|
|
59
|
-
def compute(self, batch_size=128, num_workers=
|
|
87
|
+
def compute(self, batch_size=128, num_workers=0, progress_bar: bool = False) -> float:
|
|
60
88
|
pred = torch.utils.data.DataLoader(self.pred_data, batch_size=batch_size, num_workers=num_workers)
|
|
61
89
|
true = torch.utils.data.DataLoader(self.true_data, batch_size=batch_size, num_workers=num_workers)
|
|
62
90
|
|
|
63
91
|
if progress_bar:
|
|
64
92
|
tqdm = import_tqdm_auto().tqdm
|
|
65
|
-
pred = tqdm(pred, desc="Forward predicted features")
|
|
66
|
-
true = tqdm(true, desc="Forward ground truth features")
|
|
93
|
+
pred = tqdm(total=len(pred), desc="Forward predicted features")
|
|
94
|
+
true = tqdm(total=len(true), desc="Forward ground truth features")
|
|
67
95
|
|
|
68
96
|
for batch in pred:
|
|
69
97
|
self.fid.update(batch.to(self.device), real=False)
|
|
@@ -72,6 +100,11 @@ class FID:
|
|
|
72
100
|
|
|
73
101
|
return self.fid.compute().item()
|
|
74
102
|
|
|
103
|
+
def reset(self):
|
|
104
|
+
self.pred_data = _FIDDataset()
|
|
105
|
+
self.true_data = _FIDDataset()
|
|
106
|
+
self.fid.reset()
|
|
107
|
+
|
|
75
108
|
|
|
76
109
|
@dataclass
|
|
77
110
|
class _FIDEntry:
|
|
@@ -104,6 +137,7 @@ class _FIDDataset(IterableDataset):
|
|
|
104
137
|
raise RuntimeError("Cannot open video file.")
|
|
105
138
|
n_frames = int(cap.get(self.cv2.CAP_PROP_FRAME_COUNT))
|
|
106
139
|
self.length += n_frames
|
|
140
|
+
cap.release()
|
|
107
141
|
|
|
108
142
|
@staticmethod
|
|
109
143
|
def _preprocess_image(image: Tensor) -> Tensor:
|
|
@@ -130,6 +164,8 @@ class _FIDDataset(IterableDataset):
|
|
|
130
164
|
frame = self._preprocess_image(frame)
|
|
131
165
|
yield frame
|
|
132
166
|
|
|
167
|
+
cap.release()
|
|
168
|
+
|
|
133
169
|
def __iter__(self):
|
|
134
170
|
for entry in self.content:
|
|
135
171
|
if entry.type == "image":
|
|
@@ -70,7 +70,7 @@ def iou_2d(proposal: Union[Tensor, ndarray], target: Union[Tensor, ndarray]) ->
|
|
|
70
70
|
|
|
71
71
|
inner_x1 = torch.maximum(proposal_x1, target_x1)
|
|
72
72
|
inner_y1 = torch.maximum(proposal_y1, target_y1)
|
|
73
|
-
inner_x2 = torch.minimum(proposal_x2,
|
|
73
|
+
inner_x2 = torch.minimum(proposal_x2, target_x2)
|
|
74
74
|
inner_y2 = torch.minimum(proposal_y2, target_y2)
|
|
75
75
|
|
|
76
76
|
area_proposal = (proposal_x2 - proposal_x1) * (proposal_y2 - proposal_y1)
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
from numpy import ndarray
|
|
2
|
+
from torch import Tensor
|
|
3
|
+
|
|
4
|
+
from tensorneko_util.util import dispatch, Eval
|
|
5
|
+
|
|
6
|
+
from tensorneko_util.io import read
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@Eval.later
|
|
10
|
+
def _secs_encoder():
|
|
11
|
+
from resemblyzer import VoiceEncoder
|
|
12
|
+
return VoiceEncoder()
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@dispatch
|
|
16
|
+
def secs(pred: str, real: str) -> float:
|
|
17
|
+
from resemblyzer import VoiceEncoder, preprocess_wav
|
|
18
|
+
pred_audio = preprocess_wav(read.audio(pred).audio[0].numpy())
|
|
19
|
+
real_audio = preprocess_wav(read.audio(real).audio[0].numpy())
|
|
20
|
+
return _secs_compute(pred_audio, real_audio)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@dispatch
|
|
24
|
+
def secs(pred: Tensor, real: Tensor) -> float:
|
|
25
|
+
return secs(pred.numpy(), real.numpy())
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@dispatch
|
|
29
|
+
def secs(pred: ndarray, real: ndarray) -> float:
|
|
30
|
+
from resemblyzer import VoiceEncoder, preprocess_wav
|
|
31
|
+
if len(pred.shape) == 2:
|
|
32
|
+
if pred.shape[0] == 1:
|
|
33
|
+
pred = pred.squeeze(0)
|
|
34
|
+
elif pred.shape[1] == 1:
|
|
35
|
+
pred = pred.squeeze(1)
|
|
36
|
+
else:
|
|
37
|
+
raise ValueError("The input audio must be mono.")
|
|
38
|
+
|
|
39
|
+
if len(real.shape) == 2:
|
|
40
|
+
if real.shape[0] == 1:
|
|
41
|
+
real = real.squeeze(0)
|
|
42
|
+
elif real.shape[1] == 1:
|
|
43
|
+
real = real.squeeze(1)
|
|
44
|
+
else:
|
|
45
|
+
raise ValueError("The input audio must be mono.")
|
|
46
|
+
|
|
47
|
+
pred_audio = preprocess_wav(pred)
|
|
48
|
+
real_audio = preprocess_wav(real)
|
|
49
|
+
|
|
50
|
+
return _secs_compute(pred_audio, real_audio)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _secs_compute(pred_audio: ndarray, real_audio: ndarray) -> float:
|
|
54
|
+
encoder = _secs_encoder.value
|
|
55
|
+
real_embed = encoder.embed_utterance(real_audio)
|
|
56
|
+
pred_embed = encoder.embed_utterance(pred_audio)
|
|
57
|
+
|
|
58
|
+
return float((real_embed * pred_embed).sum())
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.3.5
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: tensorneko
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.5
|
|
4
4
|
Summary: Tensor Neural Engine Kompanion. An util library based on PyTorch and PyTorch Lightning.
|
|
5
5
|
Home-page: https://github.com/ControlNet/tensorneko
|
|
6
6
|
Author: ControlNet
|
|
@@ -38,7 +38,7 @@ License-File: LICENSE
|
|
|
38
38
|
<div align="center">
|
|
39
39
|
<a href="https://www.python.org/"><img src="https://img.shields.io/pypi/pyversions/tensorneko?style=flat-square"></a>
|
|
40
40
|
<a href="https://pytorch.org/"><img src="https://img.shields.io/badge/PyTorch-%3E%3D1.9.0-EE4C2C?style=flat-square&logo=pytorch"></a>
|
|
41
|
-
<a href="https://www.pytorchlightning.ai/"><img src="https://img.shields.io/badge/Lightning-2.0.*-792EE5?style=flat-square&logo=lightning"></a>
|
|
41
|
+
<a href="https://www.pytorchlightning.ai/"><img src="https://img.shields.io/badge/Lightning-2.0.*/2.1.*-792EE5?style=flat-square&logo=lightning"></a>
|
|
42
42
|
</div>
|
|
43
43
|
|
|
44
44
|
<div align="center">
|
|
@@ -13,6 +13,7 @@ src/tensorneko.egg-info/requires.txt
|
|
|
13
13
|
src/tensorneko.egg-info/top_level.txt
|
|
14
14
|
src/tensorneko/arch/__init__.py
|
|
15
15
|
src/tensorneko/arch/auto_encoder.py
|
|
16
|
+
src/tensorneko/arch/binary_classifier.py
|
|
16
17
|
src/tensorneko/arch/gan.py
|
|
17
18
|
src/tensorneko/arch/vqvae.py
|
|
18
19
|
src/tensorneko/arch/wgan.py
|
|
@@ -27,14 +28,18 @@ src/tensorneko/callback/lr_logger.py
|
|
|
27
28
|
src/tensorneko/callback/nil_callback.py
|
|
28
29
|
src/tensorneko/callback/system_stats_logger.py
|
|
29
30
|
src/tensorneko/dataset/__init__.py
|
|
31
|
+
src/tensorneko/dataset/list_dataset.py
|
|
30
32
|
src/tensorneko/dataset/nested_dataset.py
|
|
31
33
|
src/tensorneko/dataset/round_robin_dataset.py
|
|
34
|
+
src/tensorneko/dataset/sampler/__init__.py
|
|
35
|
+
src/tensorneko/dataset/sampler/sequential_iter_sampler.py
|
|
32
36
|
src/tensorneko/debug/__init__.py
|
|
33
37
|
src/tensorneko/evaluation/__init__.py
|
|
34
38
|
src/tensorneko/evaluation/enum.py
|
|
35
39
|
src/tensorneko/evaluation/fid.py
|
|
36
40
|
src/tensorneko/evaluation/iou.py
|
|
37
41
|
src/tensorneko/evaluation/psnr.py
|
|
42
|
+
src/tensorneko/evaluation/secs.py
|
|
38
43
|
src/tensorneko/evaluation/ssim.py
|
|
39
44
|
src/tensorneko/io/__init__.py
|
|
40
45
|
src/tensorneko/io/reader.py
|
|
@@ -3,12 +3,12 @@ torchaudio>=0.9.0
|
|
|
3
3
|
torchvision>=0.10.0
|
|
4
4
|
torchmetrics>=0.7.3
|
|
5
5
|
tensorboard>=2.0.0
|
|
6
|
-
lightning
|
|
6
|
+
lightning<2.2,>=2.0
|
|
7
7
|
pillow>=8.1
|
|
8
8
|
av>=8.0.3
|
|
9
9
|
numpy>=1.20.1
|
|
10
10
|
einops>=0.3.0
|
|
11
|
-
tensorneko_util==0.3.
|
|
11
|
+
tensorneko_util==0.3.5
|
|
12
12
|
|
|
13
13
|
[:platform_system == "Windows"]
|
|
14
14
|
pysoundfile>=0.9.0
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
0.3.4
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{tensorneko-0.3.4 → tensorneko-0.3.5}/src/tensorneko/visualization/image_browser/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|