Skip to content

Instantly share code, notes, and snippets.

View sandeepkumar-skb's full-sized avatar
:octocat:
Get comfortable being uncomfortable

Sandeep Kumar Behera sandeepkumar-skb

:octocat:
Get comfortable being uncomfortable
View GitHub Profile
@sandeepkumar-skb
sandeepkumar-skb / smile_detector.py
Created August 16, 2020 20:29
Face, Eye and Smile detector in OpenCV
import cv2
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') # Load the cascade for the face.
eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml') # Load the cascade for eye
smile_cascade = cv2.CascadeClassifier('haarcascade_smile.xml') # Load the cascade for smile
def detect(gray, frame):
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
for x,y,w,h in faces:
@sandeepkumar-skb
sandeepkumar-skb / resnet_trt_int8.py
Created August 25, 2020 05:12
Sample script to run INT8 in TensorRT with calibration data on Tiny-Imagenet
import torch
from torch2trt import torch2trt
import torchvision.models as models
import tensorrt as trt
import torchvision.transforms as transforms
import torchvision.datasets as datasets
def get_trt_engine(model, inputs, max_batch_size=1, fp16_mode=True, int8_mode=False, int8_calib_dataset=None):
model_trt = torch2trt(model,
@sandeepkumar-skb
sandeepkumar-skb / TRTorch_resnet50.py
Created August 28, 2020 00:17
Running TRTorch on ResNet50 Torchvision model
import trtorch
import torch
import torchvision.models as models
rn50 = models.resnet50(pretrained=True).cuda().eval()
inp = torch.randn((1, 3, 224, 224), device='cuda')
rn50_jit_traced = torch.jit.trace(rn50, inp)
rn50_jit_scripted = torch.jit.script(rn50)
@sandeepkumar-skb
sandeepkumar-skb / Torch2TRT_resnet50.py
Last active August 31, 2020 23:36
Running inference on Torchvision ResNet50 in TensorRT using Torch2TRT
import torch
from torch2trt import torch2trt
import torchvision.models as models
import tensorrt as trt
import torchvision.transforms as transforms
import torchvision.datasets as datasets
def get_trt_engine(model, inputs, max_batch_size=1, fp16_mode=True, int8_mode=False, int8_calib_dataset=None):
model_trt = torch2trt(model,
@sandeepkumar-skb
sandeepkumar-skb / bind.cpp
Created September 1, 2020 05:00
C++ bind working
#include <iostream>
void print(int& i){
std::cout << i << "\n";
}
int main(){
int i = 10;
// Binding function print
auto foo = std::bind(&print, i);
@sandeepkumar-skb
sandeepkumar-skb / data_race.cpp
Created September 2, 2020 03:59
Creating a simplistic case of data race in C++
#include <thread>
#include <stdio.h>
int count = 0;
void counter(){
for (int i=0; i < 100000; ++i){
count++;
}
}
#include <thread>
#include <stdio.h>
#include <mutex>
int count = 0;
std::mutex writer;
void counter(){
for (int i=0; i < 100000; ++i){
writer.lock();
@sandeepkumar-skb
sandeepkumar-skb / atomic_sample.cpp
Created September 2, 2020 04:03
Sample atomic usage in C++
#include <thread>
#include <stdio.h>
#include <atomic>
std::atomic<unsigned int> count (0);
void counter(){
for (int i=0; i < 100000; ++i){
count++;
}
@sandeepkumar-skb
sandeepkumar-skb / device-prop-test.cu
Created September 16, 2020 18:34 — forked from teju85/device-prop-test.cu
Sample example to compare perf of cudaGetDeviceProperties and cudaDeviceGetAttribute
// Compiling and running this program:
// nvcc -std=c++11 device-prop-test.cu && ./a.out
#include <chrono>
#include <iostream>
using namespace std;
#define CUDA_CHECK(call) \
do { \
cudaError_t status = call; \
if(status != cudaSuccess) { \
#include <limits.h>
#include <unistd.h>
#include <csignal>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <iostream>
#include <sstream>
#include <stdexcept>