This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
from PIL import Image | |
import torch | |
import torch.nn.functional as F | |
import torchvision.transforms as transforms | |
## Fisheye Transformation | |
def get_of_fisheye(height, width, center, magnitude): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
from torch import nn | |
import torch.nn.functional as F | |
import copy | |
from torchvision import models | |
class BYOL(nn.Module): | |
def __init__(self, backbone: nn.Module, target_momentum=0.996): | |
super().__init__() | |
self.online_network = backbone |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import torch | |
from torch.utils.data.distributed import DistributedSampler | |
from torch.utils.data import DataLoader | |
#prase the local_rank argument from command line for the current process | |
parser = argparse.ArgumentParser() | |
parser.add_argument("--local_rank", default=0, type=int) | |
args = parser.parse_args() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TARGET_BATCH_SIZE, BATCH_FIT_IN_MEMORY = 256, 32 | |
accumulation_steps = int(TARGET_BATCH_SIZE / BATCH_FIT_IN_MEMORY) | |
network.zero_grad() # Reset gradients tensors | |
for i, (imgs, labels) in enumerate(dataloader): | |
preds = network(imgs) # Forward pass | |
loss = loss_function(preds, labels) # Compute loss function | |
loss = loss / accumulation_steps # Normalize our loss (if averaged) | |
loss.backward() # Backward pass | |
if (i+1) % accumulation_steps == 0: # Wait for several backward steps |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from torch import nn | |
class Network(nn.Module): | |
def __init__(self, split_gpus=False): | |
super().__init__() | |
self.module1 = ... | |
self.module2 = ... | |
self.split_gpus = split_gpus | |
if split_gpus: #considering only two gpus | |
self.module1.cuda(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
def get_inverse_pespective(perspective_matrix: np.array)-> np.array: | |
""" | |
This method calculates the inverse of prespective matrix by homography. | |
- Takes 4 random points on the floor plane(destination_plane) and calculates the corresponding points | |
on the camera image plane(src_plane) using perspective matrix. | |
- Calculates the Homography matrix to map any point in image plane to floor plane. | |
Parameters |