Skip to content

Instantly share code, notes, and snippets.

View borarak's full-sized avatar

Raktim Bora borarak

View GitHub Profile
@borarak
borarak / layers.py
Last active January 21, 2019 23:44
Add vgg layers and SSD layers
# Define the vgg layers
def vgg(cfg, i, batch_norm=False):
layers = []
in_channels = i
for v in cfg:
if v == 'M':
layers += [nn.MaxPool2d(kernel_size=2, stride=2)]
elif v == 'C':
layers += [nn.MaxPool2d(kernel_size=2, stride=2, ceil_mode=True)]
else:
@borarak
borarak / default_boxes.py
Created January 21, 2019 23:33
ssd_default_boxes
# Feature maps of teh classification layers [38*38, 19*19, 10*10, 5*5, 3*3, 1*1]
for k, f in enumerate(self.feature_maps):
for i, j in product(range(f), repeat=2):
# f[k] just represent the map size [38, 19, 10...]
f_k = self.image_size / self.steps[k]
cx = (j + 0.5) / f_k
cy = (i + 0.5) / f_k
# min_sizes are pre-computed according to formula
s_k = self.min_sizes[k]/self.image_size
import torch
from torch import nn as nn
from torch.functional import F
x = torch.tensor([[1,4,6,2],
[3,6,2,2],
[9,0,1,6],
[1,5,7,0]], dtype=torch.double)
k = torch.tensor([[1,3,0],
import cv2
img = cv2.imread("./datasets/coco2017/val2017/000000001296.jpg")
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
center = (img.shape[1]//2, img.shape[0] //2) # Get the image center
rotation_matrix = cv2.getRotationMatrix2D(center, -45, 1) # Calculate the rotation matrix
new_img = cv2.warpAffine(img, rotation_matrix, (img.shape[1], img.shape[0])) # Transform input image
original_four_corners = [(0, 0, 1), (427, 0, 1), (0, 640, 1), (427, 640, 1)]
new_corners = [np.matmul(rotation_matrix, pt) for pt in original_four_corners]
min_x = np.min([pt[0] for pt in new_corners])
max_x = np.max([pt[0] for pt in new_corners])
min_y = np.min([pt[1] for pt in new_corners])
max_y = np.max([pt[1] for pt in new_corners])
new_dimensions = (int(max_y-min_y), int(max_x-min_x))
from geometric.rotate import get_rotation_matrix, rotate_image
from PIL import Image
import numpy as np
img = np.asarray(Image.open("./datasets/coco2017/val2017/000000001296.jpg").convert('L'))
rot_matrix = get_rotation_matrix(img, angle=45, adjust_boundaries=True)
rotated_image = rotate_image(img, rot_matrix)
FROM nvidia/cuda:10.1-cudnn7-devel-ubuntu18.04
RUN echo "Installing dependencies..." && \
apt-get -y update && \
apt-get install -y build-essential \
cmake \
git \
wget \
vim \
software-properties-common \
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include "tensorflow/cc/saved_model/loader.h"
#include "tensorflow/cc/ops/const_op.h"
#include "tensorflow/cc/ops/image_ops.h"
#include "tensorflow/cc/ops/standard_ops.h"
#include "tensorflow/core/framework/graph.pb.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/graph/default_device.h"
/***
* This is a sample program to demonstrate the use of the model_loader.h files
***/
#include "./saved_model_loader.h"
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>