Category Pytorch

182. Save/Load Models Using Pytorch

I’d like to share 2 different ways to save and load a model using Pytorch. Saving The Entire Model #save model torch.save(model, PATH) #load model model = torch.load(PATH) model.eval() This save/load process has the least amount of code to implement.…

164. Combining Losses

Here is one way to combine losses using PyTorch. Let’s say we want to train a binary semantic segmentation model using Binary Cross Entropy Loss. When you look at your data, you’ve noticed that the data is quite imbalanced. So…

155. S3D (Separable 3D CNN)

I’ve learned about S3D(Separable 3D CNN) today so I like to share it here. S3D helps solve three challenges for video analysis. How to understand spatial information. (Recognizing the appearance of an object) How to understand temporal information. (Such as…

128. Tensorboard with Pytorch

Here is one way to visualize your model’s training process using tensorboard with Pytorch #Inside Code for Training from torch.utils.tensorboard import SummaryWriter() tb = SummaryWriter() #Add Metrics you want to evaluate tb.add_scalar(‘Loss’,loss,epoch) tb.add_scalar(‘Accuracy’,accuracy,epoch) tb.add_scalar(‘F1Score’,fa_score,epoch) To start a tensorboard server go…

125. Converting Arrays To Tensors

There are several ways to convert arrays to torch tensors. import torch import numpy as np data = np.array([1,2,3,4,5,6]) option1 = torch.Tensor(arr) option2 = torch.tensor(arr) option3 = torch.as_tensor(arr) option4 = torch.from_numpy(arr) Option Description 1 Make a Copy and convert array…

124. Preprocessing for Deepstream

I found out why my TensorRT engine model was not working as expected. I messed up with configuring the preprocessing step for Deepstream. When you use Deepstream to run inference, there is a property called net-scale-factor and offsets which you…

122. Extracting Inference Results Using C

A semantic segmentation model outputs a tensor shaped [Batch_size,Channel(Number of Classes),Img_Height,Img_Width] (If using Pytorch), but if you convert that to a TensorRT engine for faster inference, the output is flattened to a 1d array. Therefore the shaping being, [(Batch_size)X(Channel)X(Img_Height)X(Img_Width),] Considering…