Skip to content

Instantly share code, notes, and snippets.

int main () {
auto dp = [](double x) {
if (x <= -37)
return std::exp(x);
else if (x <= 18)
return std::log1p(std::exp(x));
else if (x <= 33.3)
return x + std::exp(-x);
else
return x;
@YashasSamaga
YashasSamaga / A0_NOTICE.md
Last active August 15, 2023 02:05
GSoC 2019 | OpenCV | Adding a CUDA backend to the DNN module

DISCLAIMER

This gist documents the Google Summer of Code project. It is not updated and hence does not indicate current status of the CUDA backend.

For updated details, please see this gist.

@YashasSamaga
YashasSamaga / yolov4.py
Last active February 18, 2024 04:03
YOLOv4 on OpenCV DNN
import cv2
import time
CONFIDENCE_THRESHOLD = 0.2
NMS_THRESHOLD = 0.4
COLORS = [(0, 255, 255), (255, 255, 0), (0, 255, 0), (255, 0, 0)]
class_names = []
with open("classes.txt", "r") as f:
class_names = [cname.strip() for cname in f.readlines()]
@YashasSamaga
YashasSamaga / D0_NOTICE.md
Last active January 19, 2022 16:51
[UNOFFICIAL] Summary of the CUDA backend in OpenCV DNN

DISCLAIMER

This gist is unofficial. It was created for personal use but have kept it public in case it would be of use to others. This document is not updated regularly and may not reflect the current status of the CUDA backend.

#!/bin/bash
# License: MIT. See license file in root directory
# Copyright(c) JetsonHacks (2017-2019)
OPENCV_VERSION=4.1.1
# Jetson Nano
ARCH_BIN=5.3
INSTALL_DIR=/usr/local
# Download the opencv_extras repository
# If you are installing the opencv testdata, ie
@YashasSamaga
YashasSamaga / Makefile
Last active January 19, 2023 09:25
OpenCV DNN Benchmark Code
g++ -I/usr/local/include/opencv4/ benchmark.cpp -lopencv_core -lopencv_imgproc -lopencv_dnn -lopencv_imgcodecs -O3 -std=c++17
@YashasSamaga
YashasSamaga / main.cu
Last active June 14, 2020 08:26
Performance comparision of different mish implementations
#include "mish.hpp"
#include <cuda_runtime.h>
#include <random>
#include <iostream>
template <class Activation>
__global__ void activate_vec1(float* __restrict__ output, const float* __restrict__ input, int n)
{
#include <cuda_runtime.h>
#include <iostream>
#include <algorithm>
#include <random>
__global__ void relu(float* output, const float* input, unsigned int* sign32, int n)
{
int i = blockIdx.x * blockDim.x + threadIdx.x;
#include <cuda_runtime.h>
#include <random>
#include <iostream>
struct relu_grad
{
__device__ float operator()(float x) { return x > 0; }
};
@YashasSamaga
YashasSamaga / main.cpp
Last active April 13, 2022 08:27
YOLOv4 OpenCV Performance Evaluation
// https://github.com/AlexeyAB/darknet/wiki/How-to-evaluate-accuracy-and-speed-of-YOLOv4
// g++ -I/usr/local/include/opencv4/ main.cpp -lopencv_core -lopencv_imgproc -lopencv_dnn -lopencv_imgcodecs -O3 -std=c++17 -lstdc++fs
#include <iostream>
#include <queue>
#include <iterator>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <chrono>