Skip to content

Instantly share code, notes, and snippets.

View pkubik's full-sized avatar

Paweł Kubik pkubik

  • Warsaw University of Technology
  • Warsaw
View GitHub Profile
@pkubik
pkubik / mobilenetv2.py
Created October 24, 2021 14:54
Keras implementation of MobileNetV2 for CIFAR-10 translated from Pytorch model
"""
Based on the model from:
https://github.com/kuangliu/pytorch-cifar
"""
import tensorflow as tf
import tensorflow.keras as keras
import tensorflow.keras.layers as kl
@pkubik
pkubik / gist:4f7f3af89724cd7bc4f6b439f3543749
Created April 13, 2021 18:48
PIP TF 2.4 backtracking
Downloading tensorflow-2.2.1-cp38-cp38-manylinux2010_x86_64.whl (516.3 MB)
Downloading tensorflow-2.2.0-cp38-cp38-manylinux2010_x86_64.whl (516.3 MB)
INFO: pip is looking at multiple versions of decorator to determine which version is compatible with other requirements. This could take a while.
Collecting decorator
Downloading decorator-5.0.5-py3-none-any.whl (8.8 kB)
Downloading decorator-4.4.2-py2.py3-none-any.whl (9.2 kB)
Downloading decorator-4.4.1-py2.py3-none-any.whl (9.2 kB)
Downloading decorator-4.4.0-py2.py3-none-any.whl (8.3 kB)
Downloading decorator-4.3.2-py2.py3-none-any.whl (9.1 kB)
Downloading decorator-4.3.1-py2.py3-none-any.whl (8.8 kB)
@pkubik
pkubik / git-sync.sh
Last active November 19, 2020 18:18
Synchronize content of two copies of the same git repository. Only tracked files are are copied. Warning - I can't use bash.
#! sh
set -e
target="$1"
if [ -z "$target" ]
then
echo "Please provide the target directory."
exit -1
@pkubik
pkubik / rename_var.py
Created November 2, 2020 21:48
Surgically rename a variable within pytorch model.
import torch
PATH = 'model.pth'
ckpt = torch.load(PATH)
# `ckpt` will likely be a nested dictionary with nested `state_dict`
ckpt['state_dict'] = {
key.replace('old_name', 'new_name'): value
for key, value in ckpt['state_dict'].items()
}
@pkubik
pkubik / timer.py
Last active May 8, 2020 12:40
Efficient timer
import time
from collections import deque
class Timer:
def __init__(self, buffer_size=10_000):
self.times = deque(maxlen=buffer_size)
self.__start = None
def __enter__(self):
@pkubik
pkubik / bar.py
Last active June 11, 2019 22:12
Very simple desktop panel PoC
#! python3
import datetime
from PySide2.QtCore import Qt, QPoint, QSize, QRect, QTimer
from PySide2.QtGui import QScreen
from PySide2.QtWidgets import QApplication, QLabel, QHBoxLayout, QFrame
from bspwm import State
@pkubik
pkubik / better-darcula.icls
Created November 14, 2018 22:01
Better Darcula
<scheme name="Better Darcula" version="142" parent_scheme="Darcula">
<metaInfo>
<property name="created">2018-11-14T23:00:57</property>
<property name="ide">Python</property>
<property name="ideVersion">2018.2.4.0.0</property>
<property name="modified">2018-11-14T23:01:13</property>
<property name="originalScheme">Better Darcula</property>
</metaInfo>
<colors>
<option name="DOCUMENTATION_COLOR" value="3c3f41" />
@pkubik
pkubik / interactive_vae_training_png.ipynb
Last active July 17, 2018 13:23
Interactive VAE/GAN training visualization (see SVG version for more detailed description).
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pkubik
pkubik / encode.py
Created February 26, 2018 01:26
Example of text cleaning and encoding.
import re
from collections import defaultdict
UNKNOWN_WORD_CODE = 1
SEQUENCE_LENGTH_LIMIT = 500 # just to protect from crashing the training process by too large example
def encode_text(text: str, encoding: dict, default=UNKNOWN_WORD_CODE):
clean_text = re.sub(r'([^\w-]+)', ' \g<0> ', text).strip()
tokens = clean_text.split()
tokens = ['#' if t.isnumeric() else t for t in tokens]
@pkubik
pkubik / gis.py
Last active December 31, 2017 15:28
Finding max-path-length-augmenting path in the graph (+ ignoring redundant nodes)
from enum import Enum
from queue import PriorityQueue
class PathMeta:
def __init__(self, pre: int, post: int):
"""
Metadata of the path passing through given edge
`pre` + `post` + 1 == length of the whole path