Package: torchkeras
Pytorch❤️KerasEnglish |简体中文The torchkeras library is a simple tool for training neural network in pytorch jusk in a keras style. 😋😋1, IntroductionWith torchkeras, You need not to write your training loop with many lines of code, all you need to do is justlike 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.importtorchimporttorchkerasmodel=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',monitor="val_acc",mode="max",plot=True)Besides，You can use torchkeras.VLog to get the dynamic training visualization any where as you like ~importtimeimportmath,randomfromtorchkerasimportVLogepochs=10batchs=30#0, init vlogvlog=VLog(epochs,monitor_metric='val_loss',monitor_mode='min')#1, log_startvlog.log_start()forepochinrange(epochs):#trainforstepinrange(batchs):#2, log_step (for training step)vlog.log_step({'train_loss':100-2.5*epoch+math.sin(2*step/batchs)})time.sleep(0.05)#evalforstepinrange(20):#3, log_step (for eval step)vlog.log_step({'val_loss':100-2*epoch+math.sin(2*step/batchs)},training=False)time.sleep(0.05)#4, log_epochvlog.log_epoch({'val_loss':100-2*epoch+2*random.random()-1,'train_loss':100-2.5*epoch+2*random.random()-1})# 5, log_endvlog.log_end()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, FeaturesThe 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.featuressupported from versionused or inspired by library✅ training progress bar3.0.0use tqdm,inspired by keras✅ training metrics3.0.0inspired by pytorch_lightning✅ notebook visualization in traning3.8.0inspired by fastai✅ early stopping3.0.0inspired by keras✅ gpu training3.0.0use accelerate✅ multi-gpus training(ddp)3.6.0use accelerate✅ fp16/bf16 training3.6.0use accelerate✅ tensorboard callback3.7.0use tensorboard✅ wandb callback3.7.0use wandb✅ VLog3.9.5use matplotlib3, Basic ExamplesYou can follow these full examples to get started with torchkeras.exampleread notebook coderun example in kaggle①kerasmodel basic 🔥🔥torchkeras.KerasModel example②kerasmodel wandb 🔥🔥🔥torchkeras.KerasModel with wandb demo③kerasmodel tunning 🔥🔥🔥torchkeras.KerasModel with wandb sweep demo④kerasmodel tensorboardtorchkeras.KerasModel with tensorboard example⑤kerasmodel ddp/tputorchkeras.KerasModel  ddp tpu examples⑥ VLog for lightgbm/ultralytics/transformers🔥🔥🔥VLog example4, Advanced ExamplesIn some using cases, because of the differences  of the model input types, you need to rewrite the StepRunner of
KerasModel. Here are some examples.examplemodel librarynotebookRLReinforcementLearning——Q-Learning🔥🔥-Q-learningReinforcementLearning——DQN-DQNCVImageClassification——Resnet-ResnetImageSegmentation——UNet-UNetObjectDetection——SSD-SSDOCR——CRNN 🔥🔥-CRNN-CTCImageClassification——SwinTransformertimmSwinObjectDetection——FasterRCNNtorchvisionFasterRCNNImageSegmentation——DeepLabV3++segmentation_models_pytorchDeeplabv3++InstanceSegmentation——MaskRCNNdetectron2MaskRCNNObjectDetection——YOLOv8 🔥🔥🔥ultralyticsYOLOv8InstanceSegmentation——YOLOv8 🔥🔥🔥ultralyticsYOLOv8NLPSeq2Seq——Transformer🔥🔥-TransformerTextGeneration——Llama🔥-LlamaTextClassification——BERTtransformersBERTTokenClassification——BERTtransformersBERT_NERFinetuneLLM——ChatGLM2_LoRA 🔥🔥🔥transformers,peftChatGLM2_LoRAFinetuneLLM——ChatGLM2_AdaLoRA 🔥transformers,peftChatGLM2_AdaLoRAFinetuneLLM——ChatGLM2_QLoRA🔥transformersChatGLM2_QLoRA_KaggleFinetuneLLM——BaiChuan13B_QLoRA🔥transformersBaiChuan13B_QLoRAFinetuneLLM——BaiChuan13B_NER 🔥🔥🔥transformersBaiChuan13B_NERFinetuneLLM——BaiChuan13B_MultiRounds 🔥transformersBaiChuan13B_MultiRoundsFinetuneLLM——Qwen7B_MultiRounds 🔥🔥🔥transformersQwen7B_MultiRoundsFinetuneLLM——BaiChuan2_13B 🔥transformersBaiChuan2_13BIf 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:算法美食屋