Skip to content

Instantly share code, notes, and snippets.

@previtus
previtus / load celeb a 32x32 dataset.py
Created April 5, 2021 22:15
celeb a dataset at 32x32 resolution
from PIL import Image
from torchvision import datasets, transforms
import torch
import torch.utils.data as data
import urllib.request
import scipy.io
import os
import imageio
import numpy as np
from os import listdir
@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