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

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.03),
                              metrics_dict = {"acc":torchmetrics.metrics.Accuracy()}
                             )
dfhistory=model.fit(epochs=30, train_data=dl_train, 
                    val_data=dl_val, patience=3, 
                    monitor="val_acc",mode="max",
                    ckpt_path='checkpoint.pt')

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
tensorboard callback
simple source 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.2.0.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

torchkeras-3.2.0-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: torchkeras-3.2.0.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.64.0 CPython/3.8.8

File hashes

Hashes for torchkeras-3.2.0.tar.gz
Algorithm Hash digest
SHA256 419a36b446856fc4f7102edc39576f4b324b691ea8fe24d842db4ae7b3b5c4b8
MD5 7331a075710f6344422a6cf2b3a43359
BLAKE2b-256 cf362cbda8ff16ade75fa66c81337c924d4b94c68507c6677b91304bae3d071c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torchkeras-3.2.0-py3-none-any.whl
  • Upload date:
  • Size: 15.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.64.0 CPython/3.8.8

File hashes

Hashes for torchkeras-3.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 40b65f1a43d8d1ab2e4f0521cf4c80bc143b1fcffb94f27ed401601bcc3c4d83
MD5 0e415a57859a6ebeebbfd55dbfe3042b
BLAKE2b-256 8dd529ac82125cbb7abdb1a0f190785f3904ea4df9e955d1be5c497049084b08

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