deeptool
์ฃผํผํฐ ๋ ธํธ๋ถ์์ PyTorch ๋ชจ๋ธ์ ๊ฐ์ฒด์งํฅ์ผ๋ก ๋ค๋ฃจ๊ธฐ ์ํ ์์ ๋ณด์กฐ ๋ผ์ด๋ธ๋ฌ๋ฆฌ.
๋ชจ๋ธ์ ์ ์ ๊ฐ PyTorch๋ก ์ง์ ์์ฑํ๋ค. ์ด ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ ๊ทธ ์ฃผ๋ณ๋ง ๋ด๋นํ๋ค โ ํ์ดํผํ๋ผ๋ฏธํฐ ์๋ ์ ์ฅ, ์ ๊ฐ ๋ฉ์๋ ์ถ๊ฐ, ํ์ต ์ค ์์ค ๊ณก์ ๋ผ์ด๋ธ ๋ ๋๋ง, ๋๋ฐ์ด์ค ์๋ ์ ํ, ํ์ต ๊ธฐ๋ก ์์ํ, ์ฒดํฌํฌ์ธํธ.
์ค์น
uv add deeptool # uv ํ๋ก์ ํธ์
pip install deeptool
import deeptool as dt
์ด ์ ์ฅ์์์ ์ง์ ๊ฐ๋ฐํ๋ ค๋ฉด:
uv sync
ํต์คํํธ
import torch
from torch import nn
from torch.nn import functional as F
import deeptool as dt
class SyntheticRegression(dt.DataModule):
def __init__(self, n=200, batch_size=32):
super().__init__()
self.save_hyperparameters()
torch.manual_seed(0)
self.X = torch.randn(n, 2)
self.y = self.X @ torch.tensor([[2.0], [-3.4]]) + 4.2
def get_dataloader(self, train):
idx = slice(0, 160) if train else slice(160, None)
return self.get_tensorloader((self.X, self.y), train, idx)
class LinearRegression(dt.Module):
def __init__(self, lr=0.03):
super().__init__()
self.save_hyperparameters()
self.net = nn.LazyLinear(1)
๋ค์ ์ ์์ ๋ฉ์๋๋ฅผ ๋ง๋ถ์ธ๋ค. ํด๋์ค๋ฅผ ๋ค์ ์ ์ํ ํ์๊ฐ ์๋ค.
@dt.add_to_class(LinearRegression)
def loss(self, y_hat, y):
return F.mse_loss(y_hat, y)
@dt.add_to_class(LinearRegression)
def configure_optimizers(self):
return torch.optim.SGD(self.parameters(), lr=self.lr)
ํ์ต์ ๋๋ฆฌ๋ฉด ์์ค ๊ณก์ ์ด ์ ์ถ๋ ฅ์ ์ค์๊ฐ์ผ๋ก ๊ฐฑ์ ๋๋ค.
trainer = dt.Trainer(max_epochs=20)
trainer.fit(LinearRegression(), SyntheticRegression())
trainer.save_checkpoint("linreg.pt")
์ ์ฒด ์์ ๋ examples/quickstart.ipynb ์ฐธ๊ณ .
ํ์ต ๊ธฐ๋ก๊ณผ ์คํ ๋น๊ต
log_dir์ ์ฃผ๋ฉด ๋ฉํ๋ฐ์ดํฐ์ ์๋ฃ๋ ์ํญ์ ์ฆ์ ๋์คํฌ์ ๋จ๊ธด๋ค.
trainer = dt.Trainer(max_epochs=50, plot=False, log_dir="runs/exp1")
trainer.fit(model, data)
๋ชจ๋ธ ์์ ์ฌ์ฉ์ ์งํ๋ ์ด๋ฆ์ ๊ทธ๋๋ก ์ด๋ค. ๊ฐ์ ์ํญ์์ ์ฌ๋ฌ ๋ฒ ๋ถ๋ฅด๋ฉด ํ๊ท ํ ์ ์ด ๋๋ค.
self.log("iou", value)
์คํ๋ง๋ค meta.json๊ณผ append-only history.jsonl์ด ์๊ธด๋ค. ์คํฌ๋ฆฝํธ์์๋
log_dir์ ์ค ๊ฒฝ์ฐ์๋ง ์ํญ๋น ํ ์ค๋ ์ถ๋ ฅํ๋ค. ๊ธฐ๋ก ์ค์ด๊ฑฐ๋ ์ค๊ฐ์ ๋ฉ์ถ
์คํ๋ ์๋ฃ๋ ์ค๊น์ง ์ฝ๊ณ ๋น๊ตํ ์ ์๋ค.
runs = dt.load_runs("runs")
figures = dt.plot_runs(runs)
plot_runs๋ ์งํ๋ง๋ค Figure ํ๋๋ฅผ ๋ง๋ค๊ณ ๊ทธ ์งํ๊ฐ ์๋ ์คํ๋ง ๊ฒน์ณ ๊ทธ๋ฆฐ๋ค.
๋ชจ๋ธ๋ง๋ค ์งํ ์ด๋ฆ์ด ๋ฌ๋ผ๋ ๋ณ๋ ์คํค๋ง๊ฐ ํ์ ์๋ค.
ํ์ต๋ฅ ์ค์ผ์ค๋ฌ
์ํญ ๊ธฐ๋ฐ scheduler๋ optimizer์ ํจ๊ป ๋ฐํํ๋ค.
def configure_optimizers(self):
optim = torch.optim.Adam(self.parameters(), lr=self.lr)
scheduler = torch.optim.lr_scheduler.StepLR(optim, step_size=10, gamma=0.1)
return optim, scheduler
์ผ๋ฐ scheduler๋ ์ํญ ๋ค step(), ReduceLROnPlateau๋ ๊ฒ์ฆ ๋ค
step(val_loss)๋ก ํธ์ถ๋๋ค. ๋งค ๋ฐฐ์น ํธ์ถ์ด ํ์ํ OneCycleLR์ AMP๋ ์์ง
์ง์ํ์ง ์๋๋ค.
์กฐ๊ธฐ ์ข ๋ฃ์ ์ต์ ๊ฐ์ค์น
๊ฐ์ ์ด ๋ฉ์ถ ๋๊น์ง ๋๋ฆฌ๊ณ ๊ฐ์ฅ ์ข์๋ ๊ฐ์ค์น๋ฅผ ์ด๋ค.
trainer = dt.Trainer(max_epochs=100, patience=5)
trainer.fit(model, data)
len(trainer.history["val_loss"]) # 24 โ 100๊น์ง ์ ๊ฐ
trainer.best_epoch, trainer.best_val_loss # (18, 0.2913)
trainer.restore_best() # 18 ์ ๋ฐํ
fit() ์ ๊ฐ์ค์น๋ฅผ ์๋์ผ๋ก ๋๋๋ฆฌ์ง ์๋๋ค. restore_best() ๋ฅผ ๋ถ๋ฅด๊ธฐ ์ ๊น์ง๋
๋ง์ง๋ง epoch ์ํ์ด๋ฏ๋ก ๋ ์์ ์ ์ฑ๋ฅ์ ๋น๊ตํ ์ ์๋ค.
๊ธฐ๋ณธ์ ๋ฉ๋ชจ๋ฆฌ ์ค๋ ์ท์ด๋ค. ํ์ผ๋ก ๋จ๊ธฐ๋ ค๋ฉด:
dt.Trainer(max_epochs=100, patience=5, best_path="best.pt")
ํ์ผ์๋ ๋ชจ๋ธ ๊ฐ์ค์น๋ง ๋ค์ด๊ฐ๋ค. optimizer ์ํ๋ restore_best() ๊ฐ ์ฝ์ง ์๋๋ฐ
Adam ๊ธฐ์ค ๋ชจ๋ธ์ 2๋ฐฐ๋ผ ๋งค epoch ์ฐ๋ฉด ๋ญ๋น๋ค. ์ต์ ์ ๋ถํฐ ํ์ต์ ์ฌ๊ฐํ ๊ณํ์ด๋ฉด
best_with_optim=True ๋ก ์ ์ฒด ์ฒดํฌํฌ์ธํธ๋ฅผ ๋จ๊ธด๋ค.
| ์ธ์ | ๊ธฐ๋ณธ | ์๋ฏธ |
|---|---|---|
snapshot_best |
True |
์ค๋ ์ท์ ๋ง๋ค ๊ฒ์ธ๊ฐ |
best_path |
None |
None ์ด๋ฉด ๋ฉ๋ชจ๋ฆฌ, ๊ฒฝ๋ก๋ฉด ํ์ผ |
best_with_optim |
False |
ํ์ผ์ optimizer ์ํ๋ ๋ฃ์ ๊ฒ์ธ๊ฐ |
patience |
None |
๋ช epoch ๊ฐ์ ์ด ์์ผ๋ฉด ๋ฉ์ถ ๊ฒ์ธ๊ฐ |
ํ์ต ํ ํ๊ฐ
p = trainer.predict(data) # ๊ฒ์ฆ์
์ ์ฒด ์ถ๋ก
p.accuracy # 0.8837
p.preds # ์ํ๋ณ ์์ธก ํด๋์ค
p.confidence # ์์ธก ํ์ ๋
p.correct # ๋ง์ท๋์ง ์ฌ๋ถ (bool ํ
์)
p = trainer.predict(data, keep_inputs=True)
p.inputs[~p.correct] # ํ๋ฆฐ ์ํ์ ์
๋ ฅ โ ์๊ฐํ์ ์ด๋ค
predsยทprobsยทconfidenceยทcorrectยทaccuracy ๋ ๋ถ๋ฅ ์ ์ฉ์ด๋ค.
ํ๊ท ๋ชจ๋ธ์ด๋ฉด p.outputs ๋ฅผ ์ง์ ์ด๋ค.
API
| ์ด๋ฆ | ์ญํ |
|---|---|
dt.add_to_class(Class) |
๋ฐ์ฝ๋ ์ดํธํ ํจ์๋ฅผ Class ์ ๋ฉ์๋๋ก ๋ฑ๋ก |
dt.HyperParameters |
save_hyperparameters() ๋ก __init__ ์ธ์๋ฅผ ์์ฑ + hparams ๋ก ์ ์ฅ |
dt.DataModule |
get_dataloader(train) ํ๋๋ง ๊ตฌํํ๋ฉด ๋๋ ๋ฐ์ดํฐ ๊ท์ฝ |
dt.Module |
forward/loss/configure_optimizers ๋ฅผ ์ฑ์ฐ๋ ๋ชจ๋ธ ๊ท์ฝ |
dt.Trainer |
fit(model, data), predict(data), restore_best(), save_checkpoint, load_checkpoint, history, best_epoch, best_val_loss |
dt.predict |
๋ชจ๋ธ๊ณผ dataloader ๋ฅผ ๋ฐ์ ๋ฐ์ดํฐ์ ์ ์ฒด ์์ธก์ ๋ชจ์๋ค |
dt.Predictions |
์์ธก ๊ฒฐ๊ณผ. predsยทprobsยทconfidenceยทcorrectยทaccuracy |
dt.ProgressBoard |
๋ผ์ด๋ธ ์์ค ๊ณก์ . Trainer(plot=True) ๊ฐ ์๋์ผ๋ก ๋ง๋ ๋ค |
dt.RunRecorder |
ํ ์คํ์ meta.json๊ณผ history.jsonl ๊ธฐ๋ก |
dt.load_runs |
์ฌ๋ฌ ์คํ์ ์์ ํ JSONL ์งํ๋ฅผ ๋ก๋ |
dt.plot_runs |
์งํ๋ณ ์คํ ๋น๊ต Figure ๋ชฉ๋ก ์์ฑ |
dt.default_device() |
cuda โ mps โ cpu |
๊ฐ๋ฐ
uv run pytest
๋ผ์ด์ผ์ค
MIT. LICENSE ์ฐธ๊ณ .
์ค๊ณ๋ d2l-ai/d2l-en์ d2l/torch.py๋ฅผ ์ฐธ๊ณ ํ๋ค.
ํด๋น ์ํ ์ฝ๋๋ modified MIT(LICENSE-SAMPLECODE)๋ก ๋ฐฐํฌ๋๋ค.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file deeptool-0.3.0.tar.gz.
File metadata
- Download URL: deeptool-0.3.0.tar.gz
- Upload date:
- Size: 146.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e28882dd576c4af6886a2378ee01aea83663e4f7520374fcf05a83091d72e6fd
|
|
| MD5 |
9d411e95e2edcd6e9a816d4297306d4d
|
|
| BLAKE2b-256 |
68fe70e31de7f1ad57e72119f72597eb1aeb091e9cfecd2d6f58eb1491b5ad2c
|
Provenance
The following attestation bundles were made for deeptool-0.3.0.tar.gz:
Publisher:
publish.yml on sciencemj/deeptool
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
deeptool-0.3.0.tar.gz -
Subject digest:
e28882dd576c4af6886a2378ee01aea83663e4f7520374fcf05a83091d72e6fd - Sigstore transparency entry: 2452935014
- Sigstore integration time:
-
Permalink:
sciencemj/deeptool@479e05d686bb6c5736f6443c18dc0c4a515a2998 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/sciencemj
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@479e05d686bb6c5736f6443c18dc0c4a515a2998 -
Trigger Event:
release
-
Statement type:
File details
Details for the file deeptool-0.3.0-py3-none-any.whl.
File metadata
- Download URL: deeptool-0.3.0-py3-none-any.whl
- Upload date:
- Size: 20.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e72b9be83a6e253fd797fd4a80df30508c87ed21e2487d2dbd456217c3a78022
|
|
| MD5 |
ba1a77b16c5a67cba3f7f7ce83de4afe
|
|
| BLAKE2b-256 |
0d487bbc6965142582b651f6ed5d59c1a0fb2e5260af495cc59baa2e66a1fa61
|
Provenance
The following attestation bundles were made for deeptool-0.3.0-py3-none-any.whl:
Publisher:
publish.yml on sciencemj/deeptool
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
deeptool-0.3.0-py3-none-any.whl -
Subject digest:
e72b9be83a6e253fd797fd4a80df30508c87ed21e2487d2dbd456217c3a78022 - Sigstore transparency entry: 2452935065
- Sigstore integration time:
-
Permalink:
sciencemj/deeptool@479e05d686bb6c5736f6443c18dc0c4a515a2998 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/sciencemj
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@479e05d686bb6c5736f6443c18dc0c4a515a2998 -
Trigger Event:
release
-
Statement type: