pytorch❤️keras
Project description
Pytorch❤️Keras
The torchkeras library is a simple tool for training neural network in pytorch jusk in a keras style. 😋😋
torchkeras ❤️ wandb: https://wandb.ai/lyhue1991/mnist_torchkeras
1, Introduction
With torchkeras, You need not to write your training loop with many lines of code, all you need to do is just
like these two steps as below:
(i) create your network and wrap it and the loss_fn together with torchkeras.KerasModel like this:
model = torchkeras.KerasModel(net,loss_fn=nn.BCEWithLogitsLoss())
a metrics_dict parameter is optional.
(ii) fit your model with the training data and validate data.
The main code of use torchkeras is like below.
import torch
import torchkeras
#use torchkeras.KerasModel
model = torchkeras.KerasModel(net,
loss_fn = nn.BCEWithLogitsLoss(),
optimizer= torch.optim.Adam(net.parameters(),lr = 0.001),
metrics_dict = {"acc":torchmetrics.Accuracy(task='binary')}
)
dfhistory=model.fit(train_data=dl_train,
val_data=dl_val,
epochs=20,
patience=3,
ckpt_path='checkpoint.pt',
monitor="val_acc",
mode="max")
This project seems somehow powerful, but the source code is very simple.
Actually, only about 200 lines of Python code.
If you want to understand or modify some details of this project, feel free to read and change the source code!!!
2, Features
Besides the basic torchkeras.KerasModel, another powerful class torchkeras.LightModel is created to support pytorch_lightning training style.
The KerasModel is much simpler, and is recommended for beginner users.
The LightModel borrows many features from the library pytorch_lightning and shows a best practice.
Although different, the usage of torchkeras.KerasModel and torchkeras.LightModel is very similar.
features | torchkeras.KerasModel 🔥🔥🔥 | torchkeras.LightModel |
---|---|---|
progress bar | ✅ | ✅ |
early stopping | ✅ | ✅ |
metrics from torchmetrics | ✅ | ✅ |
gpu training | ✅ | ✅ |
multi-gpus training(ddp) | ✅ | ✅ |
tensorboard callback | ✅ | ✅ |
pretty wandb callback | ✅ | ❌ |
other callbacks from pytorch_lightning | ❌ | ✅ |
simple code | ✅ | ❌ |
3, Basic Examples
You can follow these full examples to get started with torchkeras.
Have fun!😋😋
example | read notebook code | run example in kaggle |
---|---|---|
①kerasmodel basic 🔥🔥 | torchkeras.KerasModel example | |
②kerasmodel wandb 🔥🔥🔥 | torchkeras.KerasModel with wandb demo | |
③kerasmodel tunning 🔥🔥🔥 | torchkeras.KerasModel with wandb sweep demo | |
④kerasmodel tensorboard | torchkeras.KerasModel with tensorboard example | |
⑤kerasmodel ddp/tpu | torchkeras.KerasModel ddp tpu examples | |
⑥lightmodel basic | torchkeras.LightModel example | |
⑦lightmodel tensorboard | torchkeras.LightModel with tensorboard example |
If you want to understand or modify some details of this project, feel free to read and change the source code!!!
Any other questions, you can contact the author form the wechat official account below:
算法美食屋
Project details
Release history Release notifications | RSS feed
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
File details
Details for the file torchkeras-3.8.0.tar.gz
.
File metadata
- Download URL: torchkeras-3.8.0.tar.gz
- Upload date:
- Size: 7.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7683df9c7fb6bc5798a520006d1568f3df72cfcdc60948de5bf233b852a72a2 |
|
MD5 | a7a820d71e016b869553a26879351e29 |
|
BLAKE2b-256 | 0f1e1120a5cb0915cc1e81466c940c1227dde91657cfd008c1700ec3e0097649 |
File details
Details for the file torchkeras-3.8.0-py3-none-any.whl
.
File metadata
- Download URL: torchkeras-3.8.0-py3-none-any.whl
- Upload date:
- Size: 7.4 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c71e7c53c9de18bd3bee6f9b20838312945cc2e931522f85866fc9f72466ec0a |
|
MD5 | 80b8f5368a104856183ddbabe5db2a5e |
|
BLAKE2b-256 | 49d20cd17f58cae8fbf451a3738290b9b98843e17b6590cc1ab31fb4799cc039 |