Skip to content

Instantly share code, notes, and snippets.

View nuzrub's full-sized avatar

Cyvasse nuzrub

View GitHub Profile
@nuzrub
nuzrub / mirror_console_to_file.py
Created May 11, 2021 22:24
Little Python snippet to automatically mirror any console print to a backup log file
from datetime import datetime
import sys
class SubLogger(object):
def __init__(self, name, source, logger):
self.name = name
self.source = source
self.logger = logger
@nuzrub
nuzrub / FloatPrecision.py
Created December 6, 2020 14:12
Small Python/NumPy snippet showcasing some of the inaccuracies of floating point calculation.
import numpy as np
# Creating some random data with 4 columns centered around 10
data = np.random.randn(4, 512) + 10
data = data.astype(np.float32) #np.float64
column_means = np.mean(data, axis=1, keepdims=True)
print(column_means.reshape(-1))
# [ 9.975992 9.9283495 10.003674 10.012635 ]
# Subtracting the column mean should yield zero-centered columns
@nuzrub
nuzrub / tensorflow_object_detection_api_test.py
Last active February 26, 2021 20:00
TensorFlow Object Detection API simplified sample code for inference
from PIL import Image
import matplotlib.pyplot as plt
import tensorflow as tf
import numpy as np
import os
from object_detection.utils import label_map_util
from object_detection.utils import config_util
@nuzrub
nuzrub / tensorflow2_customloops.py
Created April 30, 2020 20:54
Writing TensorFlow 2 Custom Loops: A step-by-step guide from Keras to TensorFlow 2
# Author: Ygor Rebouças
#
### The Training Loop
#
# 0) Imports
import tensorflow as tf
import numpy as np
@nuzrub
nuzrub / BatchNormOnly.py
Last active March 25, 2020 03:51
Reproducing the main findings of the paper "Training BatchNorm and Only BatchNorm: On the Expressive Power of Random Features in CNNs"
# Reproducing the main findings of the paper "Training BatchNorm and Only BatchNorm: On the Expressive Power of Random Features in CNNs"
# Goal: Train a ResNet model to solve the CIFAR-10 dataset using only batchnorm layers, all else is frozen at their random initial state.
# https://medium.com/@ygorrebouasserpa
# https://www.linkedin.com/in/ygor-rebouças-serpa-11606093/
import tensorflow as tf
import numpy as np
import pandas as pd