Skip to content

Instantly share code, notes, and snippets.

View BloodAxe's full-sized avatar
🇺🇦
Keep calm and love Ukraine

Eugene Khvedchenya BloodAxe

🇺🇦
Keep calm and love Ukraine
View GitHub Profile
def test_loss_profiling():
loss = nn.BCEWithLogitsLoss()
with torch.autograd.profiler.profile(use_cuda=True) as prof:
input = torch.randn((8, 1, 128, 128)).cuda()
input.requires_grad = True
target = torch.randint(1, (8, 1, 128, 128)).cuda().float()
for i in range(10):
l = loss(input, target)
@BloodAxe
BloodAxe / Dual-head model with pytorch-toolbelt.py
Created January 18, 2020 06:31
This gist shows to how define dual-head model for predicting mask & global-level image class
from pytorch_toolbelt.modules import ABN, GlobalAvgPool2d
from pytorch_toolbelt.modules import decoders as D
from pytorch_toolbelt.modules import encoders as E
from torch import nn
from torch.nn import functional as F
class FPNCatSegmentationModel(nn.Module):
def __init__(
self,
@BloodAxe
BloodAxe / setup.sh
Last active January 3, 2018 15:59
Configure DigitalOcean Droplet for cloud image processing
# Prepare system
apt-get update
apt-get upgrade
apt-get install build-essential
apt-get install cmake
apt-get install git
apt-get install pkg-config
# Grab frest opencv library
curl -sL https://github.com/Itseez/opencv/archive/master.zip > opencv.zip
@BloodAxe
BloodAxe / eggs_detector.cpp
Created July 15, 2014 14:37
Image enchancement and Hough transform example
/**
* @brief Image enchancement and Hough transform example
* @author Eugene Khvedchenya <ekhvedchenya@gmail.com>
* @copyright computer-vision-talks.com/articles/how-to-detect-circles-in-noisy-image/
*/
#include <opencv2/opencv.hpp>
@BloodAxe
BloodAxe / histogram.cpp
Created September 29, 2013 18:03
Color image histogram in OpenCV
void drawHistogram(cv::Mat src, cv::Mat& histImage)
{
using namespace cv;
using namespace std;
/// Separate the image in 3 places ( B, G and R )
vector<Mat> bgr_planes;
split( src, bgr_planes );
/// Establish the number of bins
General configuration for OpenCV 2.9.0 =====================================
Version control: unknown
Platform:
Host: Linux 2.6.32-358.14.1.el6.mmapsem.x86_64 x86_64
CMake: 2.8.10.2
CMake generator: Unix Makefiles
CMake build tool: /usr/bin/gmake
Configuration: Release
@BloodAxe
BloodAxe / build-opencv-node.sh
Last active December 21, 2015 09:08
Checkout opencv and builds it for Node.js module
#!/bin/sh
cd ~/
curl -L http://www.cmake.org/files/v2.8/cmake-2.8.10.2-Linux-i386.sh > cmake.sh
sh cmake.sh --prefix='~/lib/cmake'
curl -L https://github.com/Itseez/opencv/archive/master.zip 2> /dev/null > opencv.zip
unzip opencv.zip
@BloodAxe
BloodAxe / node-js-opencv-bare-min.cpp
Last active December 21, 2015 08:49
Minimal Node.js nodule that prints OpenCV build information
#include <node.h>
#include <opencv2/opencv.hpp>
#include <string>
using namespace v8;
// This function returns a JavaScript number that is either 0 or 1.
Handle<Value> buildInformation(const Arguments& args)
{
// At the top of every function that uses anything about v8, include a
# Clone fresh copy of OpenCV
git clone https://github.com/Itseez/opencv.git opencv-node
# Prepare build and install dirs
mkdir opencv-node-build
mkdir opencv-node-bin
cd opencv-node-build
# Configure OpenCV
cmake -DCMAKE_BUILD_TYPE=RELEASE \
/**********************************************************************************
* OpenCV Rocks - Image mosaic demo
*
* This tutorial shows how to create mosaic image
* from digital photography using OpenCV.
*
* Author: Eugene Khvedchenya <ekhvedchenya@gmail.com>
*
* More information:
* - http://computer-vision-talks.com