Skip to content

Instantly share code, notes, and snippets.

View ikhlestov's full-sized avatar
🐍
Coding

Illarion ikhlestov

🐍
Coding
View GitHub Profile
def mi_linear(arg1, arg2, output_size, global_bias_start=0.0, scope=None):
"""Multiplicated Integrated Linear map:
See http://arxiv.org/pdf/1606.06630v1.pdf
A * (W[0] * arg1) * (W[1] * arg2) + (W[0] * arg1 * bias1) + (W[1] * arg2 * bias2) + global_bias.
Args:
arg1: batch x n, Tensor.
arg2: batch x n, Tensor.
output_size: int, second dimension of W[i].
global_bias_start: starting value to initialize the global bias; 0 by default.
scope: VariableScope for the created subgraph; defaults to "MILinear".
@ikhlestov
ikhlestov / tmux-cheatsheet.markdown
Created November 1, 2016 13:08 — forked from MohamedAlaa/tmux-cheatsheet.markdown
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
import hashlib
import argparse
import subprocess
parser = argparse.ArgumentParser()
parser.add_argument('--md5', type=str, required=True)
args = parser.parse_args()
script_to_run = 'some.py'
import json
import tensorflow as tf
from tensorflow.python.client import timeline
x = tf.random_normal([1000, 1000])
y = tf.random_normal([1000, 1000])
res = tf.matmul(x, y)
# Run the graph with full trace option
def composite_function(self, _input, out_features, kernel_size=3):
"""Function from paper H_l that performs:
- batch normalization
- ReLU nonlinearity
- convolution with required kernel
- dropout, if required
"""
with tf.variable_scope("composite_function"):
# BN
output = self.batch_norm(_input)
@ikhlestov
ikhlestov / multithreaded_data_provider.py
Created March 16, 2017 16:55
Tensorflow multithreading data provider
import tensorflow as tf
class MultithreadedTensorProvider():
""" A class designed to provide tensors input in a
separate threads. """
def __init__(self, capacity, sess, dtypes, shuffle_queue=False,
number_of_threads=1):
@ikhlestov
ikhlestov / 01_simple_example.py
Last active September 9, 2020 08:05
01_Profiling Tensorflow with timeline
import tensorflow as tf
from tensorflow.python.client import timeline
a = tf.random_normal([2000, 5000])
b = tf.random_normal([5000, 1000])
res = tf.matmul(a, b)
with tf.Session() as sess:
# add additional options to trace the session execution
options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE)
@ikhlestov
ikhlestov / 02_example_with_placeholders_and_for_loop.py
Created March 23, 2017 12:48
02_Profiling Tensorflow with timeline
import os
import tempfile
import tensorflow as tf
from tensorflow.contrib.layers import fully_connected as fc
from tensorflow.examples.tutorials.mnist import input_data
from tensorflow.python.client import timeline
batch_size = 100
@ikhlestov
ikhlestov / 03_merged_timeline_only_class_definition.py
Created March 23, 2017 13:32
03_Profiling Tensorflow with timeline(only class for merging timelines)
import json
class TimeLiner:
_timeline_dict = None
def update_timeline(self, chrome_trace):
# convert crome trace to python dict
chrome_trace_dict = json.loads(chrome_trace)
# for first run store full trace
@ikhlestov
ikhlestov / pytorch_as_numpy.py
Last active February 19, 2020 06:47
pytorch: pytorch as numpy
import torch
import numpy as np
numpy_tensor = np.random.randn(10, 20)
# convert numpy array to pytorch array
pytorch_tensor = torch.Tensor(numpy_tensor)
# or another way
pytorch_tensor = torch.from_numpy(numpy_tensor)