Skip to content

Instantly share code, notes, and snippets.

View Unbinilium's full-sized avatar
🌃
lost in the nowhere

Unbinilium Unbinilium

🌃
lost in the nowhere
View GitHub Profile
@Unbinilium
Unbinilium / mnist_2_pt.ipynb
Created February 28, 2022 15:10
Create Torch Script Model from MNIST
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Unbinilium
Unbinilium / torch_mnist_inferring.hpp
Last active March 2, 2022 05:25
Inferring MNIST Torchscript model
#pragma once
#include <string>
#include <vector>
#include <utility>
#include <torch/torch.h>
#include <torch/script.h>
#include <opencv2/core.hpp>
@Unbinilium
Unbinilium / data_2_mnist.py
Created February 27, 2022 06:47
Datasets to MNIST
#!/usr/bin/env python3
import os, argparse, secrets
import numpy as np
from array import *
from pathlib import Path
from PIL import Image
def data_2_mnist(data_folder:Path, img_size:int, output_folder:Path):
print("Dataset folder ->", data_folder)
@Unbinilium
Unbinilium / mnist_onnx_inferring.hpp
Last active March 2, 2022 05:26
MNIST ONNX inferring using OpenCV DNN
#pragma once
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
#include <opencv2/core.hpp>
#include <opencv2/dnn.hpp>
#include <opencv2/imgproc.hpp>
@Unbinilium
Unbinilium / migration.md
Last active May 8, 2021 11:37
Migration

I migrated my gist to my website:

  • WebSite https://unbinilium.github.io/
@Unbinilium
Unbinilium / build-pytorch-and-pytorch-vision.md
Created February 3, 2020 05:43
Build PyTorch and PyTorch Vision
  • Install dependencies
sudo apt-get install -y libopenblas-dev libblas-dev m4 cmake cython python3-dev python3-yaml python3-setuptools libavutil-dev libavcodec-dev libavformat-dev libswscale-dev
  • Build PyTorch from the source
git clone --recursive https://github.com/pytorch/pytorch
pushd pytorch
git submodule update --remote third_party/protobuf
@Unbinilium
Unbinilium / opencv-tutorial-transparent-mask-overlay-to-recognized-faces.md
Last active January 24, 2020 15:46
OpenCV Tutorial transparent mask overlay to recognized faces

As the death toll from the Wuhan coronavirus still risen, I felt anxious and helpless through everyone here were talking and laughing on New Year's Eve. Not sure what should I do and I just wrote this python3 program to make people aware of the importance of wearing respirator masks when defeating the virus.

In this program, we use CascadeClassifier to add respirators masks to the recognized faces in the capture. Before everything start, we have to import the necessary packages:

import argparse
import cv2

We use argparse to construct the argument parse for more flexible usage. The respirator image cloud be found on eBay, Google... and transparent background required as .png format. The haarcascade_frontalface_default.xml could be found at OpenCV official git repository https://github.com/opencv/opencv/tree/master/data/haarcascade.

@Unbinilium
Unbinilium / Get-started-with-OpenCV-CUDA-cpp.md
Last active October 30, 2023 05:59
Get started with OpenCV CUDA C++

First your OpenCV should be compiled with CUDA (and OpenGL) support to test all this features. Detect your CUDA hardware with OpenCV CUDA by:

#include <iostream>
using namespace std;

#include <opencv2/core.hpp>
using namespace cv;

#include <opencv2/cudaarithm.hpp>
using namespace cv::cuda;
@Unbinilium
Unbinilium / Build-OpenCV-with-CUDA-and-TBB-Visual-Studio.md
Last active March 14, 2023 13:29
Build OpenCV with CUDA and TBB Visual Studio

OpenCV is a library of programming functions mainly aimed at real-time computer vision and it officially compiled without support for NVIDIA CUDA, INTEL TTB and OpenCL library, that's why we need to rebuild OpenCV with a custom configuration manually.

CUDA is a parallel computing platform and programming model developed by Nvidia for general computing on its own GPUs (graphics processing units). CUDA enables developers to speed up compute-intensive applications by harnessing the power of GPUs for the parallelizable part of the computation.

Intel TBB (Threading Building Blocks) makes parallel performance and scalability accessible to software developers who are writing loop- and task-based applications. Build robust applications that abstract platform details and threading mechanisms while achieving performance that scales with increasing core count.

To begin with, these software libraries should be pre-installed and configured correctly:

@Unbinilium
Unbinilium / Use-undefined-array-in-cpp.md
Last active October 30, 2019 11:32
Use undefined array in cpp

In C/C++, we can define multidimensional arrays in simple words as array of arrays. Data in multidimensional arrays are stored in tabular form (in row major order). A dynamic 2D array is basically an array of pointers to arrays. So you first need to initialize the array of pointers to pointers and then initialize each 1d array in a loop. Example below using new:

#include <iostream>

int main()
{
    int row = 3, col =3;
    array = (int**) new int* [row];
    for (int i = 0; i < row; i++) array[i] = new int[col];
    for (int i = 0; i < row; i++)