owl-imdl 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. owl_imdl-1.0.0/LICENSE +9 -0
  2. owl_imdl-1.0.0/PKG-INFO +75 -0
  3. owl_imdl-1.0.0/README.md +57 -0
  4. owl_imdl-1.0.0/pyproject.toml +31 -0
  5. owl_imdl-1.0.0/setup.cfg +4 -0
  6. owl_imdl-1.0.0/src/owl/__init__.py +34 -0
  7. owl_imdl-1.0.0/src/owl/cli/__init__.py +1 -0
  8. owl_imdl-1.0.0/src/owl/cli/cmd_init.py +64 -0
  9. owl_imdl-1.0.0/src/owl/cli/cmd_version.py +3 -0
  10. owl_imdl-1.0.0/src/owl/cli/main.py +38 -0
  11. owl_imdl-1.0.0/src/owl/cli/templates/finetune.py +110 -0
  12. owl_imdl-1.0.0/src/owl/cli/templates/train.py +108 -0
  13. owl_imdl-1.0.0/src/owl/cli/templates/val_metric.py +80 -0
  14. owl_imdl-1.0.0/src/owl/cli/templates/visual.py +0 -0
  15. owl_imdl-1.0.0/src/owl/engine/__init__.py +32 -0
  16. owl_imdl-1.0.0/src/owl/engine/app.py +433 -0
  17. owl_imdl-1.0.0/src/owl/engine/engine.py +263 -0
  18. owl_imdl-1.0.0/src/owl/engine/pipeline.py +146 -0
  19. owl_imdl-1.0.0/src/owl/engine/state.py +39 -0
  20. owl_imdl-1.0.0/src/owl/toolkits/__init__.py +38 -0
  21. owl_imdl-1.0.0/src/owl/toolkits/common/__init__.py +29 -0
  22. owl_imdl-1.0.0/src/owl/toolkits/common/ckpt.py +49 -0
  23. owl_imdl-1.0.0/src/owl/toolkits/common/fmt.py +50 -0
  24. owl_imdl-1.0.0/src/owl/toolkits/common/fs.py +53 -0
  25. owl_imdl-1.0.0/src/owl/toolkits/common/image.py +55 -0
  26. owl_imdl-1.0.0/src/owl/toolkits/common/logger.py +95 -0
  27. owl_imdl-1.0.0/src/owl/toolkits/common/metrics.py +290 -0
  28. owl_imdl-1.0.0/src/owl/toolkits/common/registry.py +63 -0
  29. owl_imdl-1.0.0/src/owl/toolkits/common/validator.py +63 -0
  30. owl_imdl-1.0.0/src/owl/toolkits/criterion/__init__.py +24 -0
  31. owl_imdl-1.0.0/src/owl/toolkits/criterion/base.py +28 -0
  32. owl_imdl-1.0.0/src/owl/toolkits/data/__init__.py +28 -0
  33. owl_imdl-1.0.0/src/owl/toolkits/data/augment/__init__.py +0 -0
  34. owl_imdl-1.0.0/src/owl/toolkits/data/augment/transforms.py +68 -0
  35. owl_imdl-1.0.0/src/owl/toolkits/data/augment/types.py +114 -0
  36. owl_imdl-1.0.0/src/owl/toolkits/data/collectors/__init__.py +0 -0
  37. owl_imdl-1.0.0/src/owl/toolkits/data/collectors/owl.py +57 -0
  38. owl_imdl-1.0.0/src/owl/toolkits/data/dataloader.py +118 -0
  39. owl_imdl-1.0.0/src/owl/toolkits/data/dataset.py +83 -0
  40. owl_imdl-1.0.0/src/owl/toolkits/data/types.py +71 -0
  41. owl_imdl-1.0.0/src/owl/toolkits/evaluator/__init__.py +7 -0
  42. owl_imdl-1.0.0/src/owl/toolkits/evaluator/base.py +20 -0
  43. owl_imdl-1.0.0/src/owl/toolkits/evaluator/default.py +83 -0
  44. owl_imdl-1.0.0/src/owl/toolkits/model/__init__.py +26 -0
  45. owl_imdl-1.0.0/src/owl/toolkits/model/base.py +37 -0
  46. owl_imdl-1.0.0/src/owl/toolkits/model/types.py +22 -0
  47. owl_imdl-1.0.0/src/owl/toolkits/optimizer/__init__.py +10 -0
  48. owl_imdl-1.0.0/src/owl/toolkits/optimizer/adamw.py +7 -0
  49. owl_imdl-1.0.0/src/owl/toolkits/scheduler/__init__.py +8 -0
  50. owl_imdl-1.0.0/src/owl/toolkits/scheduler/poly.py +12 -0
  51. owl_imdl-1.0.0/src/owl/toolkits/visualizer/__init__.py +24 -0
  52. owl_imdl-1.0.0/src/owl/toolkits/visualizer/base.py +46 -0
  53. owl_imdl-1.0.0/src/owl/toolkits/visualizer/default_mask.py +33 -0
  54. owl_imdl-1.0.0/src/owl_imdl.egg-info/PKG-INFO +75 -0
  55. owl_imdl-1.0.0/src/owl_imdl.egg-info/SOURCES.txt +57 -0
  56. owl_imdl-1.0.0/src/owl_imdl.egg-info/dependency_links.txt +1 -0
  57. owl_imdl-1.0.0/src/owl_imdl.egg-info/entry_points.txt +2 -0
  58. owl_imdl-1.0.0/src/owl_imdl.egg-info/requires.txt +5 -0
  59. owl_imdl-1.0.0/src/owl_imdl.egg-info/top_level.txt +1 -0
owl_imdl-1.0.0/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 kwen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,75 @@
1
+ Metadata-Version: 2.4
2
+ Name: owl-imdl
3
+ Version: 1.0.0
4
+ Summary: IMDL template engine
5
+ Author-email: kwen <aikwen@outlook.com>
6
+ License-Expression: MIT
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: Operating System :: OS Independent
9
+ Requires-Python: >=3.10
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: loguru>=0.7.3
13
+ Requires-Dist: rich>=13.4.0
14
+ Requires-Dist: python-statemachine>=3.0.0
15
+ Requires-Dist: questionary>=2.1.1
16
+ Requires-Dist: prettytable>=3.17.0
17
+ Dynamic: license-file
18
+
19
+ # owl-imdl
20
+ ![Python Version](https://img.shields.io/badge/python->3.7-blue)
21
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
22
+
23
+ ## Installation (TestPyPI)
24
+
25
+ Currently, this package is available on **TestPyPI**. You can install it using the following command:
26
+
27
+ ```bash
28
+ pip install -i https://test.pypi.org/simple/ owl-imdl
29
+ ```
30
+
31
+ ## Manual Dependencies
32
+
33
+ To keep the package lightweight and flexible, this project does not enforce deep learning framework dependencies (to avoid version conflicts).
34
+
35
+ Please manually install the following dependencies according to your environment before use:
36
+
37
+ 1. **PyTorch**: Visit [pytorch](https://pytorch.org/get-started/locally/) to get the command for your CUDA version.
38
+ 2. Other Essentials:
39
+ ```bash
40
+ pip install numpy Pillow albumentations
41
+ ```
42
+
43
+ ## Quick Start
44
+
45
+ ### Initialize a Project
46
+
47
+ Run the following command in any directory to generate a training script (e.g., `my_project.py`):
48
+
49
+ ```bash
50
+ owl init
51
+ ```
52
+
53
+ ## Dataset Structure
54
+
55
+ ```text
56
+ my_dataset/
57
+ ├── gt/ # Ground Truth images
58
+ ├── tp/ # Tampered/Target images
59
+ └── my_dataset.json # Index file (MUST match the folder name!)
60
+ ```
61
+
62
+ JSON Format (my_dataset.json):
63
+
64
+ ```json
65
+ [
66
+ {
67
+ "tp": "tampered_image_01.jpg",
68
+ "gt": "mask_01.png"
69
+ },
70
+ {
71
+ "tp": "tampered_image_02.jpg",
72
+ "gt": "mask_02.png"
73
+ }
74
+ ]
75
+ ```
@@ -0,0 +1,57 @@
1
+ # owl-imdl
2
+ ![Python Version](https://img.shields.io/badge/python->3.7-blue)
3
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
+
5
+ ## Installation (TestPyPI)
6
+
7
+ Currently, this package is available on **TestPyPI**. You can install it using the following command:
8
+
9
+ ```bash
10
+ pip install -i https://test.pypi.org/simple/ owl-imdl
11
+ ```
12
+
13
+ ## Manual Dependencies
14
+
15
+ To keep the package lightweight and flexible, this project does not enforce deep learning framework dependencies (to avoid version conflicts).
16
+
17
+ Please manually install the following dependencies according to your environment before use:
18
+
19
+ 1. **PyTorch**: Visit [pytorch](https://pytorch.org/get-started/locally/) to get the command for your CUDA version.
20
+ 2. Other Essentials:
21
+ ```bash
22
+ pip install numpy Pillow albumentations
23
+ ```
24
+
25
+ ## Quick Start
26
+
27
+ ### Initialize a Project
28
+
29
+ Run the following command in any directory to generate a training script (e.g., `my_project.py`):
30
+
31
+ ```bash
32
+ owl init
33
+ ```
34
+
35
+ ## Dataset Structure
36
+
37
+ ```text
38
+ my_dataset/
39
+ ├── gt/ # Ground Truth images
40
+ ├── tp/ # Tampered/Target images
41
+ └── my_dataset.json # Index file (MUST match the folder name!)
42
+ ```
43
+
44
+ JSON Format (my_dataset.json):
45
+
46
+ ```json
47
+ [
48
+ {
49
+ "tp": "tampered_image_01.jpg",
50
+ "gt": "mask_01.png"
51
+ },
52
+ {
53
+ "tp": "tampered_image_02.jpg",
54
+ "gt": "mask_02.png"
55
+ }
56
+ ]
57
+ ```
@@ -0,0 +1,31 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "owl-imdl"
7
+ version = "1.0.0"
8
+ description = "IMDL template engine"
9
+ readme = "README.md"
10
+ authors = [
11
+ {name = "kwen", email = "aikwen@outlook.com"},
12
+ ]
13
+ license = "MIT"
14
+ classifiers = [
15
+ "Programming Language :: Python :: 3",
16
+ "Operating System :: OS Independent",
17
+ ]
18
+ requires-python = ">=3.10"
19
+ dependencies = [
20
+ "loguru>=0.7.3",
21
+ "rich>=13.4.0",
22
+ "python-statemachine>=3.0.0",
23
+ "questionary>=2.1.1",
24
+ "prettytable>=3.17.0",
25
+ ]
26
+
27
+ [project.scripts]
28
+ owl = "owl.cli.main:main"
29
+
30
+ [tool.setuptools.packages.find]
31
+ where = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,34 @@
1
+ import importlib
2
+ from typing import TYPE_CHECKING
3
+
4
+ try:
5
+ from importlib.metadata import version
6
+ __version__ = version("owl-imdl")
7
+ except ImportError:
8
+ __version__ = "unknown"
9
+
10
+ # IDE 提示
11
+ if TYPE_CHECKING:
12
+ from . import engine
13
+ from . import toolkits
14
+
15
+
16
+ _delayed_imports = {
17
+ "engine": ".engine",
18
+ "toolkits": ".toolkits",
19
+ }
20
+
21
+ def __getattr__(name:str):
22
+ if name in _delayed_imports:
23
+ module = importlib.import_module(_delayed_imports[name], package=__package__)
24
+ # 缓存
25
+ globals()[name] = module
26
+ return module
27
+ raise AttributeError(f"module 'owl' has no attribute '{name}'")
28
+
29
+
30
+ __all__ = [
31
+ "__version__",
32
+ "engine",
33
+ "toolkits",
34
+ ]
@@ -0,0 +1 @@
1
+ from .main import main
@@ -0,0 +1,64 @@
1
+ from pathlib import Path
2
+ import shutil
3
+ import questionary
4
+ from questionary import Choice
5
+
6
+ TEMPLATE_DIR = Path(__file__).resolve().parent / "templates"
7
+
8
+ def func(args):
9
+ choices = [
10
+ Choice(title="训练", value="train.py"),
11
+ Choice(title="微调", value="finetune.py"),
12
+ Choice(title="验证", value="val_metric.py"),
13
+ Choice(title="可视化", value="visual.py"),
14
+ ]
15
+ selected_template = questionary.select(
16
+ message="请选择一个要生成的模板 (上下键移动,回车确认):",
17
+ choices=choices
18
+ ).ask()
19
+
20
+ if not selected_template:
21
+ return
22
+
23
+ # 当前工作目录
24
+ current_cwd = Path.cwd()
25
+ # 选择的模板文件路径
26
+ src_path = TEMPLATE_DIR / selected_template
27
+ # 生成的模板文件
28
+ target_filename = selected_template
29
+ dst_path = current_cwd / target_filename
30
+
31
+ # 检查模板源文件是否存在
32
+ if not src_path.exists():
33
+ print(f"内部模板丢失: {src_path}")
34
+ return
35
+
36
+ # 文件名重复检测循环
37
+ while dst_path.exists():
38
+ print(f"文件 '{target_filename}' 在当前目录下已存在。")
39
+
40
+ # 让用户输入新名字
41
+ new_name = questionary.text(
42
+ "请输入新的文件名 (留空则取消):",
43
+ default=f"{target_filename}"
44
+ ).ask()
45
+
46
+ # 如果用户没输入直接取消
47
+ if not new_name or not new_name.strip():
48
+ print("操作已取消。")
49
+ return
50
+
51
+ # 更新目标文件名和路径并补全后缀
52
+ target_filename = new_name.strip()
53
+ if not target_filename.endswith(".py"):
54
+ target_filename += ".py"
55
+
56
+ dst_path = current_cwd / target_filename
57
+
58
+ # 复制
59
+ try:
60
+ shutil.copy(src_path, dst_path)
61
+ print(f"\n[success] 已生成文件: {dst_path.name}")
62
+ print(f" 路径: {dst_path}")
63
+ except Exception as e:
64
+ print(f"[fail] 无法写入文件: {e}")
@@ -0,0 +1,3 @@
1
+ def func(args):
2
+ from .. import __version__
3
+ print(__version__)
@@ -0,0 +1,38 @@
1
+ import argparse
2
+ from . import cmd_version, cmd_init
3
+
4
+ def main():
5
+ parser = argparse.ArgumentParser(
6
+ description="Owl - IMDL Deep Learning Training Framework CLI",
7
+ prog="owl"
8
+ )
9
+
10
+ subparsers = parser.add_subparsers(dest="command", required=True, help="可用命令")
11
+
12
+ # ==========================================
13
+ # 子命令: init (初始化)
14
+ # ==========================================
15
+ parser_init = subparsers.add_parser(
16
+ name="init",
17
+ help="初始化项目配置模板"
18
+ )
19
+ # 绑定处理函数
20
+ parser_init.set_defaults(func=cmd_init.func)
21
+
22
+ # ==========================================
23
+ # 子命令: version (版本)
24
+ # ==========================================
25
+ parser_version = subparsers.add_parser(
26
+ name="version",
27
+ help="查看版本号")
28
+ parser_version.set_defaults(func=cmd_version.func)
29
+
30
+ # ==========================================
31
+ # 解析参数并执行对应的函数
32
+ # ==========================================
33
+ args = parser.parse_args()
34
+
35
+ if hasattr(args, 'func'):
36
+ args.func(args)
37
+ else:
38
+ parser.print_help()
@@ -0,0 +1,110 @@
1
+ import copy
2
+
3
+ import torch
4
+ import torch.nn as nn
5
+ from owl.engine.app import OwlApp
6
+ from owl.engine.state import ExecMode
7
+ from owl.toolkits.data.dataloader import OwlDataLoader
8
+ from owl.toolkits.data.types import DataLoaderConfig
9
+ from owl.toolkits.model.base import OwlModel
10
+ from owl.toolkits.criterion.base import OwlCriterion
11
+ from owl.toolkits.model import MODELS
12
+ from owl.toolkits.criterion import CRITERIA
13
+ from owl.toolkits.data.augment.types import ResizeConfig
14
+
15
+
16
+ # ==========================================
17
+ # 模型
18
+ # ==========================================
19
+ @MODELS.register("dummy_model")
20
+ class DummyModel(OwlModel):
21
+ def __init__(self, in_channels=3):
22
+ super().__init__()
23
+ self.conv = nn.Conv2d(in_channels, 1, kernel_size=3, padding=1)
24
+
25
+ def forward(self, batch_data, current_epoch=0, current_step=0, **kwargs):
26
+ x = batch_data["tp_tensor"] # 篡改图输入: [B, 3, H, W]
27
+ logits = self.conv(x) # 输出 Logits: [B, 1, H, W]
28
+ return {"logits": logits}
29
+
30
+
31
+ # ==========================================
32
+ # 损失函数
33
+ # ==========================================
34
+ @CRITERIA.register("dummy_loss")
35
+ class DummyLoss(OwlCriterion):
36
+ def __init__(self):
37
+ super().__init__()
38
+ self.loss_fn = nn.BCEWithLogitsLoss()
39
+
40
+ def forward(self, model_outputs, batch_data, current_epoch=0, current_step=0, **kwargs):
41
+ logits = model_outputs["logits"]
42
+ gt = batch_data["gt_tensor"]
43
+ return self.loss_fn(logits, gt)
44
+
45
+
46
+ def main():
47
+ # ==========================================
48
+ # 数据集配置
49
+ # ==========================================
50
+ # 指向你项目中的测试数据集目录 (根据运行位置调整)
51
+ dataset_paths = ["example","example"]
52
+ common_aug = [
53
+ ResizeConfig(height=256, width=256, p=1.0)
54
+ ]
55
+
56
+ # DataLoader 基础参数字典
57
+ base_dl_config = DataLoaderConfig(
58
+ batch_size=2,
59
+ num_workers=0,
60
+ shuffle=False,
61
+ pin_memory=False,
62
+ persistent_workers=False,
63
+ drop_last=False,
64
+ )
65
+
66
+ # 训练集 Loader
67
+ train_dl_config = copy.deepcopy(base_dl_config)
68
+ train_dl_config["shuffle"] = True
69
+ train_loader = OwlDataLoader(
70
+ dataset_paths=dataset_paths,
71
+ dataloader_config=train_dl_config,
72
+ aug_configs=common_aug
73
+ )
74
+
75
+ # 验证集 Loader (关闭打乱)
76
+ val_dl_config =copy.deepcopy(base_dl_config)
77
+ val_dl_config["shuffle"] = False
78
+ val_loader = OwlDataLoader(
79
+ dataset_paths=dataset_paths,
80
+ dataloader_config=val_dl_config,
81
+ aug_configs=common_aug
82
+ )
83
+
84
+ # ==========================================
85
+ # 启动 Owl Engine
86
+ # ==========================================
87
+ app = OwlApp()
88
+ # 微调需要添加权重,同时设置finetune=true
89
+ p = ""
90
+ app.launch(
91
+ mode=ExecMode.TRAIN, # 训练模式
92
+ max_epochs=10,
93
+ ckpt_autosave=False, # 自动保存
94
+ checkpoint_path=p,
95
+ finetune=True,
96
+ device="cuda" if torch.cuda.is_available() else "cpu",
97
+ # 挂载组件
98
+ model_name="dummy_model",
99
+ model_cfg={"in_channels": 3},
100
+ criterion_name="dummy_loss",
101
+ criterion_cfg={},
102
+
103
+ # 数据集
104
+ owl_train_loader=train_loader,
105
+ owl_val_loaders=val_loader,
106
+ )
107
+
108
+
109
+ if __name__ == "__main__":
110
+ main()
@@ -0,0 +1,108 @@
1
+ import copy
2
+
3
+ import torch
4
+ import torch.nn as nn
5
+ from owl.engine.app import OwlApp
6
+ from owl.engine.state import ExecMode
7
+ from owl.toolkits.data.dataloader import OwlDataLoader
8
+ from owl.toolkits.data.types import DataLoaderConfig
9
+ from owl.toolkits.model.base import OwlModel
10
+ from owl.toolkits.criterion.base import OwlCriterion
11
+ from owl.toolkits.model import MODELS
12
+ from owl.toolkits.criterion import CRITERIA
13
+ from owl.toolkits.data.augment.types import ResizeConfig
14
+
15
+
16
+ # ==========================================
17
+ # 模型
18
+ # ==========================================
19
+ @MODELS.register("dummy_model")
20
+ class DummyModel(OwlModel):
21
+ def __init__(self, in_channels=3):
22
+ super().__init__()
23
+ self.conv = nn.Conv2d(in_channels, 1, kernel_size=3, padding=1)
24
+
25
+ def forward(self, batch_data, current_epoch=0, current_step=0, **kwargs):
26
+ x = batch_data["tp_tensor"] # 篡改图输入: [B, 3, H, W]
27
+ logits = self.conv(x) # 输出 Logits: [B, 1, H, W]
28
+ return {"logits": logits}
29
+
30
+
31
+ # ==========================================
32
+ # 损失函数
33
+ # ==========================================
34
+ @CRITERIA.register("dummy_loss")
35
+ class DummyLoss(OwlCriterion):
36
+ def __init__(self):
37
+ super().__init__()
38
+ self.loss_fn = nn.BCEWithLogitsLoss()
39
+
40
+ def forward(self, model_outputs, batch_data, current_epoch=0, current_step=0, **kwargs):
41
+ logits = model_outputs["logits"]
42
+ gt = batch_data["gt_tensor"]
43
+ return self.loss_fn(logits, gt)
44
+
45
+
46
+ def main():
47
+ # ==========================================
48
+ # 数据集配置
49
+ # ==========================================
50
+ # 指向你项目中的测试数据集目录 (根据运行位置调整)
51
+ dataset_paths = ["example","example"]
52
+ common_aug = [
53
+ ResizeConfig(height=256, width=256, p=1.0)
54
+ ]
55
+
56
+ # DataLoader 基础参数字典
57
+ base_dl_config = DataLoaderConfig(
58
+ batch_size=2,
59
+ num_workers=0,
60
+ shuffle=False,
61
+ pin_memory=False,
62
+ persistent_workers=False,
63
+ drop_last=False,
64
+ )
65
+
66
+ # 训练集 Loader
67
+ train_dl_config = copy.deepcopy(base_dl_config)
68
+ train_dl_config["shuffle"] = True
69
+ train_loader = OwlDataLoader(
70
+ dataset_paths=dataset_paths,
71
+ dataloader_config=train_dl_config,
72
+ aug_configs=common_aug
73
+ )
74
+
75
+ # 验证集 Loader (关闭打乱)
76
+ val_dl_config =copy.deepcopy(base_dl_config)
77
+ val_dl_config["shuffle"] = False
78
+ val_loader = OwlDataLoader(
79
+ dataset_paths=dataset_paths,
80
+ dataloader_config=val_dl_config,
81
+ aug_configs=common_aug
82
+ )
83
+
84
+ # ==========================================
85
+ # 启动 Owl Engine
86
+ # ==========================================
87
+ app = OwlApp()
88
+
89
+ app.launch(
90
+ mode=ExecMode.TRAIN, # 训练模式
91
+ max_epochs=10,
92
+ ckpt_autosave=True, # 自动保存
93
+ device="cuda" if torch.cuda.is_available() else "cpu",
94
+
95
+ # 挂载组件
96
+ model_name="dummy_model",
97
+ model_cfg={"in_channels": 3},
98
+ criterion_name="dummy_loss",
99
+ criterion_cfg={},
100
+
101
+ # 数据集
102
+ owl_train_loader=train_loader,
103
+ owl_val_loaders=val_loader,
104
+ )
105
+
106
+
107
+ if __name__ == "__main__":
108
+ main()
@@ -0,0 +1,80 @@
1
+ import copy
2
+ import pathlib
3
+
4
+ import torch
5
+ import torch.nn as nn
6
+ from owl.engine.app import OwlApp
7
+ from owl.engine.state import ExecMode
8
+ from owl.toolkits.data.dataloader import OwlDataLoader
9
+ from owl.toolkits.data.types import DataLoaderConfig
10
+ from owl.toolkits.model.base import OwlModel
11
+ from owl.toolkits.criterion.base import OwlCriterion
12
+ from owl.toolkits.model import MODELS
13
+ from owl.toolkits.criterion import CRITERIA
14
+ from owl.toolkits.data.augment.types import ResizeConfig
15
+
16
+
17
+ # ==========================================
18
+ # 模型
19
+ # ==========================================
20
+ @MODELS.register("dummy_model")
21
+ class DummyModel(OwlModel):
22
+ def __init__(self, in_channels=3):
23
+ super().__init__()
24
+ self.conv = nn.Conv2d(in_channels, 1, kernel_size=3, padding=1)
25
+
26
+ def forward(self, batch_data, current_epoch=0, current_step=0, **kwargs):
27
+ x = batch_data["tp_tensor"] # 篡改图输入: [B, 3, H, W]
28
+ logits = self.conv(x) # 输出 Logits: [B, 1, H, W]
29
+ return {"logits": logits}
30
+
31
+ def main():
32
+ # ==========================================
33
+ # 数据集配置
34
+ # ==========================================
35
+ # 指向你项目中的测试数据集目录 (根据运行位置调整)
36
+ dataset_paths = ["example", "example"]
37
+ common_aug = [
38
+ ResizeConfig(height=256, width=256, p=1.0)
39
+ ]
40
+
41
+ # DataLoader 基础参数字典
42
+ base_dl_config = DataLoaderConfig(
43
+ batch_size=2,
44
+ num_workers=0,
45
+ shuffle=False,
46
+ pin_memory=False,
47
+ persistent_workers=False,
48
+ drop_last=False,
49
+ )
50
+
51
+ # 验证集 Loader (关闭打乱)
52
+ val_dl_config =copy.deepcopy(base_dl_config)
53
+ val_dl_config["shuffle"] = False
54
+ val_loader = OwlDataLoader(
55
+ dataset_paths=dataset_paths,
56
+ dataloader_config=val_dl_config,
57
+ aug_configs=common_aug
58
+ )
59
+
60
+ # ==========================================
61
+ # 启动 Owl Engine
62
+ # ==========================================
63
+ app = OwlApp()
64
+ # 权重
65
+ p = r""
66
+ app.launch(
67
+ mode=ExecMode.VALIDATE, # 测试模型
68
+ checkpoint_path=p,
69
+ device="cuda" if torch.cuda.is_available() else "cpu",
70
+ # 挂载组件
71
+ model_name="dummy_model",
72
+ model_cfg={"in_channels": 3},
73
+
74
+ # 数据集
75
+ owl_val_loaders=val_loader,
76
+ )
77
+
78
+
79
+ if __name__ == "__main__":
80
+ main()
File without changes
@@ -0,0 +1,32 @@
1
+ import importlib
2
+ from typing import TYPE_CHECKING
3
+
4
+ if TYPE_CHECKING:
5
+ from . import app
6
+ from . import engine
7
+ from . import pipeline
8
+ from . import state
9
+
10
+ _delayed_imports = {
11
+ "app": ".app",
12
+ "engine": ".engine",
13
+ "pipline": ".pipeline",
14
+ "state": ".state",
15
+ }
16
+
17
+ def __getattr__(name:str):
18
+ if name in _delayed_imports:
19
+ module = importlib.import_module(_delayed_imports[name], package=__package__)
20
+ # 缓存
21
+ globals()[name] = module
22
+ return module
23
+
24
+ raise AttributeError(f"module 'core' has no attribute '{name}'")
25
+
26
+
27
+ __all__ = [
28
+ "app",
29
+ "engine",
30
+ "pipeline",
31
+ "state",
32
+ ]