Package: slackker
Introducing slackker! :fire:slackkeris a python package for monitoring your ML model training status in real-time on Slack & Telegram. It can send you update for your ML model training progress and send final report with graphs when the training finishes. So now you don't have to sit in front of the machine all the time. You can quickly go and grab coffee :coffee: downstairs or run some errands and still keep tracking the progress while on the move without loosing your peace of mind.Requirements:slack_sdk>=3.19.0andmatplotlibTable of contents :notebook:InstallationGetting started with slackker callbacksSetup slackkerUse slackker callbacks with KerasImport slackker for KerasCreate slackker object for kerasCall slackker object into model.fit()Final code for KerasUse slackker callbacks with LightningImport slackker for LightningCreate slackker object for lightningCall slackker object in Trainer moduleFinal code for LightningSupportCitationMaintainerInstallation :arrow_down:Install slackker fromPyPiis recommended. slackker is compatible withPython >= 3.6and runs on Linux, MacOS X and Windows.Installing slackker in your environment is easy. Just use below pip command:pipinstallslackkerGetting started with slackker callbacksSetup slackkerSlack:How to setup slackker for your slack channelTelegram:How to setup slackker for TelegramUse slackker callbacks withKerasImport slackker for KerasImportslackker.callbackswith following line:fromslackker.callbacks.kerasimportSlackUpdate# for slackorfromslackker.callbacks.kerasimportTelegramUpdate# for telegramCreate slackker object for kerasCreate slackker object.# for Slackslackker_object=SlackUpdate(token="xoxb-123234234235-123234234235-adedce74748c3844747aed",channel="A04AAB77ABC",ModelName='Keras_NN',export='png',SendPlot=True,verbose=0)or# for Telegramslackker_update=TelegramUpdate(token="1234567890:AAAAA_A111BBBBBCCC2DD3eEe44f5GGGgGG",ModelName='Simple_NN',export='png',SendPlot=True,verbose=0)token:(string)Slack app/Telegram tokenchannel:(string)Slack channel where you want to receive updatesModelName:(string)Name for your model. This same name will be used in future for title of the generated plots.export:(string)default"png": Format for plots to be exported.(supported formats: eps, jpeg, jpg, pdf, pgf, png, ps, raw, rgba, svg, svgz, tif, tiff)SendPlots:(Bool)defaultFalse: If set toTrueit will export history of model, both training and validation, save it in the format given inexportargument and send graphs to slack channel when training ends. If set toFalseit will not send exported graphs to slack channel.verbose:(int)default0: You can sent the verbose level up to 3.verbose = 0No loggingverbose = 1Info loggingverbose = 2Debug/In-depth loggingCall slackker object into model.fit()Now you can call slackker object into callbacks argument just like any other callbacks object.history=model.fit(x_train,y_train,epochs=3,batch_size=16,verbose=1,validation_data=(x_val,y_val),callbacks=[slackker])Final code for Keras# Import library for kerasfromslackker.callbacks.kerasimportslackUpdate# Train-Test split for your keras modelx_train,x_test,y_train,y_test=train_test_split(x,y,train_size=0.8)x_train,x_val,y_train,y_val=train_test_split(x_train,y_train,train_size=0.8)# Build keras modelmodel=Sequential()model.add(Dense(8,activation='relu',input_shape=(IMG_WIDTH,IMG_HEIGHT,DEPTH)))model.add(Dense(3,activation='softmax'))model.compile(optimizer='rmsprop',loss='categorical_crossentropy',metrics=['accuracy'])# Create Slackker objectslack_update=slackUpdate(token="xoxb-123234234235-123234234235-adedce74748c3844747aed48499bb",channel="A04AAB77ABC",modelName='SampleModel',export='png',sendPlot=True,verbose=0)# Call Slackker object in model.fit() callbackshistory=model.fit(x_train,y_train,epochs=3,batch_size=16,verbose=1,validation_data=(x_val,y_val),callbacks=[slack_update])Use slackker callbacks withLightningImport slackker for LightningImportslackker.callbackswith following line:fromslackker.callbacks.lightningimportSlackUpdate# for slackorfromslackker.callbacks.lightningimportTelegramUpdate# for telegramCreate slackker object for lightning# for Slackslackker_update=SlackUpdate(token="xoxb-123234234235-123234234235-adedce74748c3844747aed",channel="A04AAB77ABC",ModelName='Lightning NN',TrackLogs=['train_loss','train_acc','val_loss','val_acc'],monitor="val_loss",export='png',SendPlot=True,verbose=0)or# for Telegramslackker_update=TelegramUpdate(token="1234567890:AAAAA_A111BBBBBCCC2DD3eEe44f5GGGgGG",ModelName="Lightning NN Testing",TrackLogs=['train_loss','train_acc','val_loss','val_acc'],monitor="val_loss",export='png',SendPlot=True,verbose=0)token:(string)Slack app/Telegram tokenchannel:(string)Slack channel where you want to receive updatesModelName:(string)Name for your model. This same name will be used in future for title of the generated plots.TrackLogs:(list)List of logs you want slackker to send.monitor:(string)This metric will be used to determine best Epochexport:(string)default"png": Format for plots to be exported.(supported formats: eps, jpeg, jpg, pdf, pgf, png, ps, raw, rgba, svg, svgz, tif, tiff)SendPlots:(Bool)defaultFalse: If set toTrueit will export history of model, both training and validation, save it in the format given inexportargument and send graphs to slack channel when training ends. If set toFalseit will not send exported graphs to slack channel.verbose:(int)default0: You can sent the verbose level up to 3.verbose = 0No loggingverbose = 1Info loggingverbose = 2Debug/In-depth loggingCall slackker object in Trainer moduleNow you can call slackker object into callbacks argument just like any other callbacks object.trainer=Trainer(max_epochs=2,callbacks=[slackker_update])Final code for Lightningimporttorchimporttorch.nnasnnfromtorch.utils.dataimportDataLoaderimporttorchvisionastvimporttorch.nn.functionalasFfromlightning.pytorchimportLightningModule,Trainerfromlightning.pytorch.callbacksimportModelCheckpoint,Callbackfromlightning.pytorch.loggersimportCSVLoggerfromslackker.callbacks.lightningimportSlackUpdatefromslackker.callbacks.lightningimportTelegramUpdateclassLightningModel(LightningModule):def__init__(self):super().__init__()self.fc1=nn.Linear(28*28,256)self.fc2=nn.Linear(256,128)self.out=nn.Linear(128,10)defforward(self,x):batch_size,_,_,_=x.size()x=x.view(batch_size,-1)x=F.relu(self.fc1(x))x=F.relu(self.fc2(x))returnself.out(x)defconfigure_optimizers(self):optimizer=torch.optim.Adam(self.parameters(),lr=1e-3)returnoptimizerdeftraining_step(self,batch,batch_idx):x,y=batchy_hat=self.forward(x)# calculate Lossloss=F.cross_entropy(y_hat,y)#calculate accuracy_,predictions=torch.max(y_hat,dim=1)correct_predictions=torch.sum(predictions==y)accuracy=correct_predictions/y.shape[0]self.log("train_loss",loss,on_epoch=True)self.log("train_acc",accuracy,on_epoch=True)returnlossdefvalidation_step(self,batch,batch_idx):x,y=batchy_hat=self.forward(x)# calculate Lossloss=F.cross_entropy(y_hat,y)#calculate accuracy_,predictions=torch.max(y_hat,dim=1)correct_predictions=torch.sum(predictions==y)accuracy=correct_predictions/y.shape[0]self.log("val_loss",loss)self.log("val_acc",accuracy)returnlosstrain_data=tv.datasets.MNIST(".",train=True,download=True,transform=tv.transforms.ToTensor())test_data=tv.datasets.MNIST(".",train=False,download=True,transform=tv.transforms.ToTensor())train_loader=DataLoader(train_data,batch_size=128)test_loader=DataLoader(test_data,batch_size=128)model=LightningModel()# slackker checkpoint for slackslackker_update=SlackUpdate(token="xoxb-123234234235-123234234235-adedce74748c3844747aed",channel="A04AAB77ABC",ModelName='Lightning NN',TrackLogs=['train_loss','train_acc','val_loss','val_acc'],monitor="val_loss",export='png',SendPlot=True,verbose=0)trainer=Trainer(max_epochs=2,callbacks=[slackker_update])trainer.fit(model,train_loader,test_loader)Support :sparkles:If you get stuck, we’re here to help. The following are the best ways to get assistance working through your issue:Use ourGithub Issue Trackerfor reporting bugs or requesting features.
Contribution are the best way to keepslackkeramazing :muscle:If you want to contribute please referContributor's Guidefor how to contribute in a helpful and collaborative way :innocent:Citation :page_facing_up:Please cite slackker in your publications if this is useful for your project/research. Here is an example BibTeX entry:@misc{siddheshgunjal2023slackker,title={slackker},author={Siddhesh Gunjal},year={2023},howpublished={\url{https://github.com/siddheshgunjal/slackker}},}Maintainer :sunglasses: