Skip to content

Instantly share code, notes, and snippets.

View RomanSteinberg's full-sized avatar

Roman Steinberg RomanSteinberg

  • Vision Systems
  • Rostov-on-Don
View GitHub Profile
@RomanSteinberg
RomanSteinberg / draw
Created May 26, 2020 10:04
stream measurement
import json
from pathlib import Path
import pandas as pd
# from matplotlib.pyplot import plt
from matplotlib import pyplot as plt
%matplotlib inline
with Path('/home/roman/dev/vinteo/backend/measurement.json').open() as f:
m = json.load(f)
FROM tensorflow/tensorflow:1.15.0-gpu-py3
RUN addgroup --gid 1001 user && \
adduser --disabled-password --gecos '' -u 1000 --gid 1001 --home /home/user recogniser
WORKDIR /home/user
RUN apt-get update && \
apt-get -y install --no-install-recommends --no-upgrade build-essential cmake \
libopenblas-dev liblapack-dev libx11-dev libgtk-3-dev cuda-toolkit-10-0
@RomanSteinberg
RomanSteinberg / train.py
Created November 1, 2019 12:41
Tensorflow 2.0 VAE example
from __future__ import absolute_import, division, print_function, unicode_literals
from tensorflow.keras import layers
try:
# %tensorflow_version only exists in Colab.
%tensorflow_version 2.x
except Exception:
pass
import tensorflow as tf
@RomanSteinberg
RomanSteinberg / redis_json.py
Created October 16, 2019 14:48
redis json sample code
import redis
import json
data = {
'foo': 'bar',
'd': {'a': 1}
}
r = redis.StrictRedis()
r.execute_command('JSON.SET', 'doc', '.', json.dumps(data))
@RomanSteinberg
RomanSteinberg / test_qt_vs_mx.py
Last active September 6, 2019 12:20
test_qt_vs_mx
import cv2
import sys
import numpy as np
import mxnet as mx
from PyQt5.QtWidgets import QApplication
QApplication(sys.argv) # comment it
@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'
@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 / 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 / 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 / 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