Skip to content

Instantly share code, notes, and snippets.

Verifying that +quasimondo is my openname (Bitcoin username). https://onename.io/quasimondo
@Quasimondo
Quasimondo / rgb2yuv_yuv2rgb.py
Last active March 18, 2024 21:01
RGB to YUV and YUV to RGB conversion for Numpy
import numpy as np
#input is a RGB numpy array with shape (height,width,3), can be uint,int, float or double, values expected in the range 0..255
#output is a double YUV numpy array with shape (height,width,3), values in the range 0..255
def RGB2YUV( rgb ):
m = np.array([[ 0.29900, -0.16874, 0.50000],
[0.58700, -0.33126, -0.41869],
[ 0.11400, 0.50000, -0.08131]])
@Quasimondo
Quasimondo / parseafpk.py
Created August 10, 2017 09:35
Parse *.afpk file and extract peaks, landmarks and hashes
import struct
import numpy as np
def afpk2peaks(peakfilename):
PEAK_FMT = '<2i'
PEAK_MAGIC = 'audfprintpeakV00' # 16 chars, FWIW
""" Read back a set of (time, bin) pairs written by peaks_save """
peaks = []
fmtsize = struct.calcsize(PEAK_FMT)
@Quasimondo
Quasimondo / sdl_opengl_player.cpp
Created June 27, 2019 09:11
Corrected version of VLC SDL OpenGL player example that is compatible with libvlc 4.0.0
//g++ sdl_opengl_player.cpp $(pkg-config --cflags --libs libvlc sdl2 gl)
/* Licence WTFPL */
/* Written by Pierre Lamot */
#include <stdio.h>
#include <stdlib.h>
#include <exception>
#include <mutex>
import os
import numpy as np
import threading
from imageio import imwrite,imread
from scipy.ndimage import zoom
class Corona():
def __init__(self):
self.infectionProbability = 0.02
self.lethalProbability = 0.02
import numpy as np
import cv2
import time
import torch
import torch.nn.functional as F
kernel = np.ones((41, 41) ).astype(np.float32)
cv_input = (np.random.random(size=(500,500))>0).astype(np.float32)
kernel_tensor = torch.Tensor(kernel).cuda().unsqueeze(0).unsqueeze(0)
40,5.770906432748538
78,5.923830409356725
83,7.939619883040936
87,5.833187134502924
118,5.39122807017544
125,5.565643274853802
196,7.127046783625732
200,5.97953216374269
250,5.631140350877193
254,7.2331871345029235
@Quasimondo
Quasimondo / LeakySine.py
Last active December 26, 2020 14:08
A self-adjusting blend between Sine and LeakyRelu activation. No idea if this makes any sense.
import torch
import torch.nn as nn
import torch.nn.functional as F
class LeakySine(nn.Module):
def __init__(self, w0 =30.0, blend=0.75, slope = 0.2):
super().__init__()
self.blend = nn.Parameter(torch.ones(1, 1)*blend)
self.slope = nn.Parameter(torch.zeros(1, 1)+slope)
self.w0 = w0
@Quasimondo
Quasimondo / gist:7e1068e488e20f194d37ba80696b55d8
Last active December 9, 2023 09:17
A possible fix for "failed call to cuInit: CUDA_ERROR_NO_DEVICE: no CUDA-capable device"
This is a dreaded error that seems pop up its ugly head again and again, in particular after upgrading CUDA or Tensorflow.
Typcially it looks like this:
2020-12-30 17:31:40.829615: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.11.0
2020-12-30 17:31:42.149768: I tensorflow/compiler/jit/xla_cpu_device.cc:41] Not creating XLA devices, tf_xla_enable_xla_devices not set
2020-12-30 17:31:42.150368: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcuda.so.1
2020-12-30 17:31:42.176643: E tensorflow/stream_executor/cuda/cuda_driver.cc:328] failed call to cuInit: CUDA_ERROR_NO_DEVICE: no CUDA-capable device is detected
Here is a solution that currently seems to work on my system,
with Cuda 11.0 and Tensorflow 2.4.0, you can try it if all the
'''
Usage:
python quickwatermark.py [path to folder that contains images to waternark]
This will go through all the files in that folder, try to open them and add
the filename as text on top of the image. The watermarked images will be stored
in a subfolder of the chosen folder called "watermarked"
'''