This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kmc2 | |
from sklearn.cluster import MiniBatchKMeans | |
from skimge.color import lab2rgb, rgb2lab | |
def get_colors(array, clusters=3): | |
labs = rgb2lab([array]).squeeze() | |
seeding = kmc2.kmc2(labs, clusters) | |
kmeans = MiniBatchKMeans(n_clusters = clusters, init=seeding) | |
kmeans.fit(np.squeeze(labs)) | |
LABELS = kmeans.labels_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from scipy.ndimage.morphology import binary_erosion | |
from keras.utils import to_categorical | |
from fast_slic.avx2 import SlicAvx2 | |
def clip_to_superpixel(image, z, num_segments=100, erosion=12, threshold=0.5, iou_thresh=0.5): | |
fast_slic = SlicAvx2(num_components=num_segments, compactness=10, quantize_level=1) | |
segments = fast_slic.iterate(image) | |
onehot = to_categorical(segments, num_classes=num_segments, dtype='uint8') | |
threshold = (np.max(z)+np.min(z))*threshold |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright 2017 The TensorFlow Authors. 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, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def recall_top_k(y_true, y_pred): | |
# get batch size | |
batch_size = y_pred.shape[0] | |
# get pairwise distances | |
dists = _pairwise_distances(y_pred) | |
# get indexes of the closest item in the batch predictions | |
# (item itself is always the top_k, so hence getting the second top K) | |
# top_k function gives indexes for the highest values so subtracting from 2(or a high enough number) to invert the matrix |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env bash | |
pip3 uninstall pillow | |
apt install \ | |
libjpeg-turbo8-dev \ | |
zlib1g-dev \ | |
libtiff5-dev \ | |
liblcms2-dev \ | |
libfreetype6-dev \ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"lines": { | |
"blueline": { | |
"name": "Blue Line", | |
"color": "blue", | |
"type": "subway" | |
}, | |
"redline": { | |
"name": "Red Line", | |
"color": "red", |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import aria2p | |
# parellel run: | |
# aria2c --enable-rpc --rpc-listen-all | |
# Spawn aria server | |
import subprocess | |
subprocess.call(['gnome-terminal', '-e', 'aria2c --enable-rpc --rpc-listen-all']) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import thinplate as tps | |
from PIL import Image | |
import morphops | |
import cv2 | |
# helper function for https://github.com/cheind/py-thin-plate-spline | |
import thinplate as tps | |
from PIL import Image | |
import cv2 |