Skip to content

Instantly share code, notes, and snippets.

View RomanSteinberg's full-sized avatar

Roman Steinberg RomanSteinberg

View GitHub Profile
@RomanSteinberg
RomanSteinberg / train.py
Created July 24, 2018 14:20
Dataset + Estimator + Keras Model
from tensorflow.python.keras.models import Model
from tensorflow.python.keras.layers import Dense, Input, Dropout
def imgs_input_fn(filenames, labels=None, perform_shuffle=False, repeat_count=1, batch_size=1):
"""
Creates tf.data.Dataset object.
Args:
filenames (list:
labels (list):
@RomanSteinberg
RomanSteinberg / example.py
Last active July 25, 2018 14:32
Estimator fail because of folder
import numpy as np
import tensorflow as tf
experiment_folder = '/output/'
input_shape = [299, 299, 3]
def imgs_input_fn(filenames, labels=None, perform_shuffle=False, repeat_count=1, batch_size=1):
"""
@RomanSteinberg
RomanSteinberg / log_git.py
Created September 18, 2018 13:29
log commit hash
import git
repo = git.Repo(search_parent_directories=True)
opt_file.write('branch: %s\n' % repo.active_branch)
opt_file.write('sha: %s\n' % repo.head.object.hexsha)
@RomanSteinberg
RomanSteinberg / heap.js
Last active September 20, 2018 07:48
Heap and priority queue
class Heap {
constructor() {
this.container = [null];
}
isRoot(ind) {
return ind == 1;
}
swap(ind1, ind2) {
@RomanSteinberg
RomanSteinberg / analyze.py
Created November 29, 2018 14:06
TypeForm Analyze
import pandas as pd
import json
# input parameters
quiz_res_file = '/home/roman/temp/pre_survey/quiz_result.csv'
quiz_descr_file = '/home/roman/temp/pre_survey/quiz_description.json'
# main
df = pd.read_csv(quiz_res_file)
description = json.load(open(quiz_descr_file))
@RomanSteinberg
RomanSteinberg / problem.py
Created December 12, 2018 12:59
Freeing buffers strange behavior
# Description:
# This script is a minimal example of a freeing buffer strange behavior. Originally it contains error diagnosed
# by PyTorch:
# "RuntimeError: Trying to backward through the graph a second time, but the buffers have already been freed.
# Specify retain_graph=True when calling backward the first time."
#
# One can find statements which can be changed to remove error.
import torch
from torch import nn, cuda
@RomanSteinberg
RomanSteinberg / benchmark.py
Created February 25, 2019 15:36
Benchmark parallel execution
from multiprocessing import Process, Queue, Event
from queue import Empty as QueueEmpty
from random import randint, seed
from time import monotonic as now
from datetime import timedelta
TASKS_COUNT = 12
ARRAY_SIZE = 2_000_000
POOL_SIZE = 2
@RomanSteinberg
RomanSteinberg / run.py
Created March 7, 2019 08:56
Scheme to run application with profiling and without
import yaml
def get_option():
# get option from config or env or something
return yaml.load(open('config.yaml'))['production']
def measure(method):
# measures metrics for method
@RomanSteinberg
RomanSteinberg / cat.py
Created April 24, 2019 08:22
Toy example. Approaching mechanic and approaching after retreat mechanic.
class Cat:
def __init__(self):
self.start_position = np.array([1, 1])
self.velocity = 7
self.reached = False
self.room = np.array([100, 100]) # выход за границы комнаты не критичен
def move_generator(self):
pos = self.start_position
while True:
@RomanSteinberg
RomanSteinberg / convert.py
Created July 16, 2019 09:55
PyTorch -> TensorRT
import tensorrt as trt
import os
import torch
import onnx
TRT_LOGGER = trt.Logger(trt.Logger.WARNING)
def convert_to_trt(image_width, image_height):
onnx_file_path = 'model.onnx'