Skip to content

Instantly share code, notes, and snippets.

View kukuruza's full-sized avatar

kukuruza

  • Carnegie Mellon University
  • Pittsburgh PA, USA
View GitHub Profile
@kukuruza
kukuruza / labels_gtav_to_20classes.py
Last active July 16, 2018 10:46
Convert GTA5 labels to github.com/mil-tokyo/MCD_DA compatible format (it will have 20 classes)
'''
For each colored label map that GTAV provides,
create a grayscale label map for 20 classes with pixels values in [0, 19].
'''
import os, os.path as op
import numpy as np
import cv2
from glob import glob
from progressbar import ProgressBar
@kukuruza
kukuruza / labels_cityscrapes_to_20classes.py
Last active May 8, 2018 19:45
Make Cityscrapes labels compatible with github.com/mil-tokyo/MCD_DA (turn 33 classes into 20 classes).
'''
For each gtFine_labelIds file of Cityscrapes dataset,
create a grayscale label map synthetic<->real task
with 20 classes with pixels values in [0, 19],
where #19 is the background.
The classes are compatible with github.com/mil-tokyo/MCD_DA.
'''
import os, os.path as op
import numpy as np
@kukuruza
kukuruza / update_watcher.py
Created October 4, 2017 15:03
A simple utility class to wait until a file in the filesystem has changed.
# Usage:
# watcher = UpdateWatcher(changing_file_path)
# while True:
# watcher.wait_for_update()
# # Do my stuff.
import os, os.path as op
import time
import logging
@kukuruza
kukuruza / tf-generate-embeddings.py
Last active May 19, 2017 21:52
Example of generating embeddings for images from a saved model (tensorflow)
# imports and other stuff
# example constants and instances of classes
data = Data() # some data provider
model = Model() # some model
batch_size = 16
pretrained_model_path = 'model/my_model'
log_dir = 'logs'
@kukuruza
kukuruza / cifar10_vis_excitations.py
Last active January 30, 2023 12:56
Visualize deeper layers in Tensorflow by displaying images which gain the highest response from neurons. Written for cifar10 model.
# Copyright 2015 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@kukuruza
kukuruza / gist_cifar10_train.py
Last active November 4, 2024 17:36
Tensorflow: visualize convolutional filters (conv1) in Cifar10 model
from math import sqrt
def put_kernels_on_grid (kernel, pad = 1):
'''Visualize conv. filters as an image (mostly for the 1st layer).
Arranges filters into a grid, with some paddings between adjacent filters.
Args:
kernel: tensor of shape [Y, X, NumChannels, NumKernels]
pad: number of black pixels around each filter (between them)
@kukuruza
kukuruza / cifar10_train_and_eval.py
Created March 5, 2016 23:42
tensorflow: train and evaluate Cifar10 model during the same run. Train and test data are evaluated and sent to tensorboard.
# !!! Note for cifar10_train_and_eval.py !!!
#
# 1. Put this file into tensorflow/models/image/cifar10 directory.
# 2. For this file to work, you need to comment out tf.image_summary() in
# file tensorflow/models/image/cifar_input.py
#
# Copyright 2015 Google Inc. All Rights Reserved.
#