Skip to main content

pytorch❤️keras

Project description

Pytorch❤️Keras

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


Open In Kaggle

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, less than 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 much more powerful class torchkeras.LightModel is created to support many other features.

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!😋😋

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.6.0.tar.gz (17.9 kB view details)

Uploaded Source

Built Distribution

torchkeras-3.6.0-py3-none-any.whl (19.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for torchkeras-3.6.0.tar.gz
Algorithm Hash digest
SHA256 738b91c6cb19b6cb3e5eefded5b38d556aa15448b2cbf2137c488a14b6d6e9bf
MD5 f67ffbb1755b2f8afe6c141ea10b1de8
BLAKE2b-256 18c83948fe56c1f2b4b90eb01da05e85a815958013829f7003b3bb20e06d9117

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for torchkeras-3.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 83b96b5fbf213a40ba9b496b47733ec5130bf1ad0fc39183e7bceb2e1817eaa7
MD5 c355039cfdb2972ac14a2c70002059cb
BLAKE2b-256 c3f6781df6c79deb7401c251f411b34a1349ea49218a1e18858d591a261ae9de

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