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
# Remember to remove the old model! | |
# rm *.tflite | |
from typing import Optional | |
def create_lanczos_resize_func_edgetpu(images_shape: Tuple[int], dim: int, factor: int, edgetpu=True): | |
name = "lanczos_resize_%s_%d_%d" % ("_".join(map(str, images_shape)), dim, factor) | |
ctor = lambda: create_lanczos_resize_func(images_shape, dim, factor) | |
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
# The kernel size is 15 instead of 5 for greater detail. | |
dim = 15 | |
kernel = np.squeeze(create_lanczos_resize_kernel(dim).numpy()[:, :, 0, 0]) | |
plt.contourf(np.linspace(-dim, dim, dim * 2 + 1), np.linspace(-dim, dim, dim * 2 + 1), kernel) | |
plt.colorbar() | |
plt.show() |
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 create_lanczos_resize_func_edgetpu(images_shape: Tuple[int], dim: int, factor: int, edgetpu=True): | |
name = "lanczos_resize_%s_%d_%d" % ("_".join(map(str, images_shape)), dim, factor) | |
ctor = lambda: create_lanczos_resize_func(images_shape, dim, factor) | |
return create_func_edgetpu(images_shape, ctor, name, edgetpu) | |
def create_lanczos_resize_func(images_shape: Tuple[int], dim: int, factor: int): | |
kernel = create_lanczos_resize_kernel(dim) | |
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
# Remember to remove the old model! | |
# rm *.tflite | |
import json | |
import urllib.request | |
def generate_edgetpu_model(log: logging.Logger, images_shape: Tuple[int], func: callable, name: str): | |
"""Convert tf.function to Edge TPU model.""" |
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
# Remember to remove the old model! | |
# rm *.tflite | |
import subprocess | |
from tensorflow.lite.python.interpreter import load_delegate | |
def create_motion_blur_func_edgetpu(images_shape, dim, angle, edgetpu=True): | |
name = "motion_blur_%s_%d_%.2f" % ("_".join(map(str, images_shape)), dim, angle) | |
ctor = lambda: create_motion_blur_func(images_shape, dim, angle) |
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 logging | |
from pathlib import Path | |
def create_motion_blur_func(images_shape: Tuple[int], dim: int, angle: float): | |
kernel = create_motion_blur_kernel(dim, angle) | |
# This is new: input signature definition | |
@tf.function(input_signature=[tf.TensorSpec(images_shape, tf.float32)]) | |
def motion_blur_func(images): |
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 PIL import Image | |
def create_motion_blur_func(dim: int, angle: float): | |
kernel = create_motion_blur_kernel(dim, angle) | |
def motion_blur_func(images): | |
return tf.nn.depthwise_conv2d(images, kernel, strides=[1] * 4, padding="SAME") | |
return motion_blur_func |
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 matplotlib.pyplot as plt | |
plt.rcParams["image.cmap"] = "hot" | |
# 25x25 kernel pointing straight to the east | |
dim = 25 | |
kernel = np.squeeze(create_motion_blur_kernel(dim, (90/180) * np.pi).numpy()[:, :, 0, 0]) | |
plt.contourf(np.linspace(-dim//2, dim//2, dim), np.linspace(-dim//2, dim//2, dim), kernel) | |
plt.colorbar() | |
plt.show() |
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 typing import Tuple, Union | |
import numpy as np | |
from skimage.draw import line_aa | |
import tensorflow as tf | |
def create_motion_blur_kernel(dim: int, angle: float) -> tf.Tensor: | |
# Define a disk which contains the dim x dim square | |
radius = np.sqrt(0.5 * dim**2) |
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
{ | |
"embeddings": [ | |
{ | |
"tensorName": "GitLab developer experience clusters", | |
"tensorShape": [ | |
173, | |
258 | |
], | |
"tensorPath": "https://gist.githubusercontent.com/vmarkovtsev/4bd05fdd761e49a7bbbca87381e65c9c/raw/38801e9740529ac2c9ac7884fc3e8623bb37caad/data.tsv", | |
"metadataPath": "https://gist.githubusercontent.com/vmarkovtsev/4bd05fdd761e49a7bbbca87381e65c9c/raw/38801e9740529ac2c9ac7884fc3e8623bb37caad/meta.tsv" |