Skip to content

Instantly share code, notes, and snippets.

@avmoldovan
avmoldovan / tf_ring_buffer.py
Created June 12, 2020 18:47 — forked from louiskirsch/tf_ring_buffer.py
A tensorflow ring buffer implementation
class RingBuffer:
def __init__(self, scope_name, components, size):
"""
Create a new ring buffer of size `size`.
Each item in the ring buffer is a tuple of variables of size `len(components)`.
:param scope_name: A scope name for the newly created variables
:param components: Defines the type of items in the buffer. An iterable of tuples (name: str, shape: Iterable, dtype)
:param size: The maximum size of the buffer
@avmoldovan
avmoldovan / hook_activations.py
Created June 9, 2020 20:29 — forked from Tushar-N/hook_activations.py
Pytorch code to save activations for specific layers over an entire dataset
import torch
import torch.nn as nn
import torch.nn.functional as F
import torchvision.models as tmodels
from functools import partial
import collections
# dummy data: 10 batches of images with batch size 16
dataset = [torch.rand(16,3,224,224).cuda() for _ in range(10)]