Skip to content

Instantly share code, notes, and snippets.

Avatar

kukuruza

  • Carnegie Mellon University
  • Pittsburgh PA, USA
View GitHub Profile
@kukuruza
kukuruza / labels_gtav_to_20classes.py
Last active Jul 16, 2018
Convert GTA5 labels to github.com/mil-tokyo/MCD_DA compatible format (it will have 20 classes)
View labels_gtav_to_20classes.py
'''
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
Make Cityscrapes labels compatible with github.com/mil-tokyo/MCD_DA (turn 33 classes into 20 classes).
View labels_cityscrapes_to_20classes.py
'''
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 Oct 4, 2017
A simple utility class to wait until a file in the filesystem has changed.
View update_watcher.py
# 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
Example of generating embeddings for images from a saved model (tensorflow)
View tf-generate-embeddings.py
# 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 Jan 17, 2019
Visualize deeper layers in Tensorflow by displaying images which gain the highest response from neurons. Written for cifar10 model.
View cifar10_vis_excitations.py
# 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 Mar 4, 2021
Tensorflow: visualize convolutional filters (conv1) in Cifar10 model
View gist_cifar10_train.py
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 Mar 5, 2016
tensorflow: train and evaluate Cifar10 model during the same run. Train and test data are evaluated and sent to tensorboard.
View cifar10_train_and_eval.py
# !!! 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.
#