Skip to content

Instantly share code, notes, and snippets.

@dmitrysarov
dmitrysarov / sacred_exp_print.py
Created February 1, 2021 14:16
Print sacred experiments from FileObserver
import pandas as pd
import os
import json
def flatten_dict(d):
"""
transform dict of dicts to single level dict
"""
fd = {}
for k, v in d.items():

devops

Segmentation fault

can you do:

gdb python

and in gdb:

r main.py

@dmitrysarov
dmitrysarov / start_on_free_mem.py
Created August 6, 2020 22:15
start process if memory free
import subprocess, os
import re
import click
def find_free_gpu(amount_of_space):
#in Mb
nvidia_ouput = subprocess.check_output(['nvidia-smi'])
pid_memory = re.findall('(\d+)MiB\s/\s(\d+)MiB', str(nvidia_ouput), re.DOTALL)
print(pid_memory)
for gpu_num, (used, whole) in enumerate(pid_memory):
function FindProxyForURL(url, host) {
PROXY = "PROXY 10.211.55.4:3128"
// Apple.com via proxy
if (shExpMatch(host,"*philips.com*")) {
return PROXY;
}
if (shExpMatch(host,"https://confluence.atlas.philips.com")) {
return PROXY;
}
@dmitrysarov
dmitrysarov / start_on_free_mem.py
Created March 13, 2020 16:00
Start command on free enough GPU
import subprocess, os
import re
import click
def find_free_gpu(amount_of_space):
@dmitrysarov
dmitrysarov / cv2.videoWrite.py
Last active January 17, 2020 14:57
How to write sequence of frames to video file in cv2
def write_avi(frames, path):
'''
frames - 3D numpy array (seq, height, width)
path - result avi file path. Extantion of file have to be .avi
'''
def norm(x):
x = x - x.min()
x = x / x.max()
return (x*255).astype(np.uint8)
frames = norm(frames)
import subprocess
import re
import pprint
nvidia_ouput = subprocess.check_output(['nvidia-smi'])
part = re.findall('Usage(.+)', str(nvidia_ouput), re.DOTALL)
pid_memory = re.findall('\s(\d)\s+(\d+).+?\s(\d+MiB)', str(part), re.DOTALL)
user_dict = {}
print('='*50)
for gpu_num, pid, memory in pid_memory:
print('GPU number: ', gpu_num)
@dmitrysarov
dmitrysarov / iterative_hist.py
Last active October 7, 2019 13:53
If data is too large, this class can iteratively absorb data
import numpy as np
import matplotlib.pyplot as plt
class Iterative_hist(object):
'''
Collect distribution information in iterative manner.
Useful when whole data not fit memory.
Usage:
if min and max data value is not known, call set_min_max() method, iterative, on hall dataset
call add_data() method, for data addition
@dmitrysarov
dmitrysarov / image_analiser.py
Created October 3, 2019 12:06
Simple tool implemented in jupyter for image dynamic range and frequency analysis.
# %matplotlib inline
%matplotlib notebook
from ipywidgets import interact, widgets, Layout
import matplotlib.pyplot as plt
from matplotlib.image import AxesImage
from IPython.display import display
from numpy.fft import fftshift, fft2, ifft2, ifftshift
import time
from skimage import transform