Skip to content

Instantly share code, notes, and snippets.

@previtus
previtus / miwae_simplified.py
Last active March 30, 2021 19:56
VAE experiments
# Based on implementations
# - vae core https://github.com/pytorch/examples/blob/master/vae/main.py
# - miwae https://github.com/yoonholee/pytorch-vae
# - notes on VAE from the article at https://iopscience.iop.org/article/10.3847/PSJ/ab9a52 (but can be taken from elsewhere too)
from __future__ import print_function
import argparse
import torch
import torch.utils.data
from torch import nn, optim
# https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_gui/py_trackbar/py_trackbar.html#trackbar
import cv2
import numpy as np
class GUIHandler(object):
def onChangeSend(self,x):
self.A = cv2.getTrackbarPos('A', self.window_name)
@previtus
previtus / Mock Settings.py
Last active February 20, 2021 19:24
Mock Settings
# v1
import mock
settings = mock.Mock()
settings.foo = 42
# v2
# works even when checking for non-existing entries...
@previtus
previtus / win10 + tf-gpu
Last active March 13, 2020 19:36
Tensorflow-gpu versions
Safe combination for Windows 10 (crazy, eh?)
GPU: GeForce 1050 Ti
Working:
Cuda 10 -> cuda_10.0.130_411.31_win10
Cudnn for it -> cudnn-10.0-windows10-x64-v7.6.5.32(for CUDA 10.0).zip
Python 3.7.7
Tensorflow-gpu 1.14.0 -> pip3 install --upgrade tensorflow-gpu==1.14.0
@previtus
previtus / colors_for_plots.py
Created January 2, 2020 18:33
Colors for plots in python from matlibplot
import numpy as np
good_colors = [ #qualitative - http://colorbrewer2.org/#type=qualitative&scheme=Set1&n=6
(228, 26, 28), #red
(55, 126, 184), #blue
(77, 175, 74), #lightgreen
(152, 78, 163), #violet
(255, 127, 0), #orange
(255, 255, 51), #yellow
(166, 86, 40), #brown orange
(247, 129, 191) #pink
@previtus
previtus / gist:4d1b7e2605a2a7afdf51510173efe573
Created October 30, 2019 11:36
select a random 30k subset and copy it
find SOURCEDIR/ -type f | shuf -n $(shuf -i30000-30000 -n1) | tr '\n' '\0' | xargs -0 -n1 cp -t TARGETDIR/
@previtus
previtus / pad.sh
Last active April 6, 2022 16:59
Pad images with ffmpeg
# add padding to the image to be at 360x360 px
ffmpeg -i image.jpg -qscale 0 -vf "pad=360:360:360:360:color=black" imagePad.jpg
# auto overwrite
ffmpeg -y -i image.jpg -qscale 0 -vf "pad=360:360:360:360:color=black" image.jpg
# for all files in a folder
for file in *.jpg; do ffmpeg -y -i $file -qscale 0 -vf "pad=360:360:360:360:color=black" $file; done
@previtus
previtus / LWSdemo.py
Last active October 23, 2019 18:45
Tesing LWS
import librosa
import numpy as np
# Variables setup:
fft_size=2048
window_size=2048 # window size
hop_size=512 # window shift size
sample_rate=44100
lws_L = 5
@previtus
previtus / adding a new remote (target) for the same repo
Last active April 20, 2020 20:51
Migration of git repositories (copy to another one with history)
# New remote
git remote add newremote https://github.com/user/repo.git
git push newremote master
@previtus
previtus / examplePrediction.py
Last active September 4, 2019 18:26
example prediction for ChangeDetectionProject (sample code to explain a concept, not to run as it might have some typos)
import matplotlib, os
if not('DISPLAY' in os.environ):
matplotlib.use("Agg")
import DataLoader, DataPreprocesser, Dataset, Debugger, Settings, ModelHandler, Evaluator
from timeit import default_timer as timer
from datetime import *
months = ["unk","jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"]
month = (months[datetime.now().month])