Skip to content

Instantly share code, notes, and snippets.

@vadimkantorov
vadimkantorov / perlin.py
Last active February 15, 2024 10:36
Perlin noise in PyTorch
# ported from https://github.com/pvigier/perlin-numpy/blob/master/perlin2d.py
import torch
import math
def rand_perlin_2d(shape, res, fade = lambda t: 6*t**5 - 15*t**4 + 10*t**3):
delta = (res[0] / shape[0], res[1] / shape[1])
d = (shape[0] // res[0], shape[1] // res[1])
grid = torch.stack(torch.meshgrid(torch.arange(0, res[0], delta[0]), torch.arange(0, res[1], delta[1])), dim = -1) % 1
@HybridDog
HybridDog / ssim_perceptual_downscaling.c
Last active June 26, 2024 18:29
SSIM-based perceptual image downscaling for PNG images
// SPDX-License-Identifier: MIT
//
// This program contains an implementation of SSIM-based perceptual image
// downscaling for PNG images.
// The program can be twice as fast when compiled with -Ofast.
// The program behaviour can be adjusted with predefined preprocessor macros:
// * -DTILEABLE: Assume images wrap around at corners. This should be enabled
// when downscaling tileable textures.
// * -DGAMMA_INCORRECT: Downscale without applying the sRGB EOTF and OETF.
// When downscaling images with symbolic meaning, e.g. screenshots of text or
@yrevar
yrevar / imagenet1000_clsidx_to_labels.txt
Last active November 8, 2024 06:50
text: imagenet 1000 class idx to human readable labels (Fox, E., & Guestrin, C. (n.d.). Coursera Machine Learning Specialization.)
{0: 'tench, Tinca tinca',
1: 'goldfish, Carassius auratus',
2: 'great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias',
3: 'tiger shark, Galeocerdo cuvieri',
4: 'hammerhead, hammerhead shark',
5: 'electric ray, crampfish, numbfish, torpedo',
6: 'stingray',
7: 'cock',
8: 'hen',
9: 'ostrich, Struthio camelus',
@szagoruyko
szagoruyko / gist:b6e70f6c6be9a8399c10
Last active August 29, 2015 14:15
removeDescriptors
function removeDescriptors(net)
for i,val in pairs(net.modules) do
if tostring(val):find('cudnn') then
for name,field in pairs(val) do
if name:find('Desc') then
val[name] = nil
end
end
val.algType = nil
val.iDesc = nil
@toshi-k
toshi-k / LReLU.lua
Last active June 6, 2016 11:10
LeakyReLU (Torch 7)
local LReLU, parent = torch.class('nn.LReLU','nn.Module')
function LReLU:__init(a)
parent.__init(self)
self.a = a or 0.1
self.ReLU_p = nn.ReLU()
end
function LReLU:updateOutput(input)
self.output:resizeAs(input)
@koseki
koseki / jp-prefectures.html
Last active September 24, 2024 07:45
Japanese Prefectures 日本の都道府県 Text, JS, HTML 漢字, ローマ字, 都道府県コード
<select>
<option value="1">Hokkaido</option>
<option value="2">Aomori</option>
<option value="3">Iwate</option>
<option value="4">Miyagi</option>
<option value="5">Akita</option>
<option value="6">Yamagata</option>
<option value="7">Fukushima</option>
<option value="8">Ibaraki</option>
<option value="9">Tochigi</option>