Skip to main content

pytorch❤️keras

Project description

Pytorch❤️Keras

English | 简体中文

The torchkeras library is a simple tool for training neural network in pytorch jusk in a keras style. 😋😋

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()).

(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",
                    plot = True
                   )

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

The main features supported by torchkeras are listed below.

Versions when these features are introduced and the libraries which they used or inspired from are given.

features supported from version used or inspired by library
✅ training progress bar 3.0.0 use tqdm,inspired by keras
✅ training metrics 3.0.0 inspired by pytorch_lightning
✅ notebook visualization in traning 3.8.0 inspired by fastai
✅ early stopping 3.0.0 inspired by keras
✅ gpu training 3.0.0 use accelerate
✅ multi-gpus training(ddp) 3.6.0 use accelerate
✅ fp16/bf16 training 3.6.0 use accelerate
✅ tensorboard callback 3.7.0 use tensorboard
✅ wandb callback 3.7.0 use wandb

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
Open In Kaggle

②kerasmodel wandb 🔥🔥🔥 torchkeras.KerasModel with wandb demo
Open In Kaggle

③kerasmodel tunning 🔥🔥🔥 torchkeras.KerasModel with wandb sweep demo
Open In Kaggle

④kerasmodel tensorboard torchkeras.KerasModel with tensorboard example
⑤kerasmodel ddp/tpu torchkeras.KerasModel ddp tpu examples
Open In Kaggle

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

torchkeras-3.8.5.tar.gz (19.7 MB view details)

Uploaded Source

Built Distribution

torchkeras-3.8.5-py3-none-any.whl (19.7 MB view details)

Uploaded Python 3

File details

Details for the file torchkeras-3.8.5.tar.gz.

File metadata

  • Download URL: torchkeras-3.8.5.tar.gz
  • Upload date:
  • Size: 19.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.0

File hashes

Hashes for torchkeras-3.8.5.tar.gz
Algorithm Hash digest
SHA256 a5d80ef05774c43ddf6ad0c5c9164b8898766f28e0fcc0e40144f21250a3051a
MD5 7a0ace321b6af525e8424a47660941b0
BLAKE2b-256 32954931c544245ae86157290ff62c42452e00d26ec4fcd6f63f7957f53ee011

See more details on using hashes here.

File details

Details for the file torchkeras-3.8.5-py3-none-any.whl.

File metadata

  • Download URL: torchkeras-3.8.5-py3-none-any.whl
  • Upload date:
  • Size: 19.7 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.0

File hashes

Hashes for torchkeras-3.8.5-py3-none-any.whl
Algorithm Hash digest
SHA256 e69376cea72e4e3be61dd05c4bf5b2f22891a303f6504aa8c344edbb3d76b761
MD5 c4493dda64b4834ab78fe57e67019508
BLAKE2b-256 1c966d176c38cc20f64016b61ef7192a8f198cfa712fdd669d3387b9f373e51a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page