Skip to content

Instantly share code, notes, and snippets.

View bloc97's full-sized avatar
🧢

bloc97

🧢
  • Université de Montréal
  • Canada
View GitHub Profile
@trygvebw
trygvebw / find_noise.py
Last active June 21, 2024 15:31
A "reverse" version of the k_euler sampler for Stable Diffusion, which finds the noise that will reconstruct the supplied image
import torch
import numpy as np
import k_diffusion as K
from PIL import Image
from torch import autocast
from einops import rearrange, repeat
def pil_img_to_torch(pil_img, half=False):
image = np.array(pil_img).astype(np.float32) / 255.0
@innat
innat / Gradient_Accumulation_TF2.py
Last active February 11, 2023 22:18
Gradient Accumulation with Custom fit in TF.Keras. MNIST example.
import tensorflow as tf
# credit: https://stackoverflow.com/a/66524901/9215780
class CustomTrainStep(tf.keras.Model):
def __init__(self, n_gradients, *args, **kwargs):
super().__init__(*args, **kwargs)
self.n_gradients = tf.constant(n_gradients, dtype=tf.int32)
self.n_acum_step = tf.Variable(0, dtype=tf.int32, trainable=False)
self.gradient_accumulation = [tf.Variable(tf.zeros_like(v, dtype=tf.float32),
trainable=False) for v in self.trainable_variables]
@mateuszwojt
mateuszwojt / disney_brdf.glsl
Created August 13, 2019 01:51
Disney Principled BRDF GLSL shader implementation
// Principled PBR Path tracer. Except where otherwise noted:
// Copyright © 2019 Markus Moenig Distributed under The MIT License.
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
@p2or
p2or / blender-generate-mix-shader-example.py
Created June 24, 2019 10:37
Example on how to generate gloss diffuse shader via pyhon #Blender #BSE
# for https://blender.stackexchange.com/q/143599/3710
import bpy
mat_name = "Material_Name"
# check whether the material already exists
if bpy.data.materials.get(mat_name):
mat = bpy.data.materials[mat_name]
else:
@KdotJPG
KdotJPG / OpenSimplex2S.java
Last active June 19, 2024 15:44
Visually isotropic coherent noise algorithm based on alternate constructions of the A* lattice.
/**
* K.jpg's OpenSimplex 2, smooth variant ("SuperSimplex")
*
* More language ports, as well as legacy 2014 OpenSimplex, can be found here:
* https://github.com/KdotJPG/OpenSimplex2
*/
public class OpenSimplex2S {
private static final long PRIME_X = 0x5205402B9270C86FL;
@rjeschke
rjeschke / NeetJavaSound.java
Created September 11, 2011 19:26
Low latency javax.sound.sampled API
package streaming;
import java.util.concurrent.Semaphore;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.Line;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.Mixer;
@monkstone
monkstone / lut.LUT.java
Created July 12, 2011 18:15
Java sin/cos lookup table library
/**
* Copyright (c) 2011 Martin Prout
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* http://creativecommons.org/licenses/LGPL/2.1/
*
@geraldyeo
geraldyeo / fastTrig.as
Created May 24, 2011 03:52
Fast and accurate sine/cosine approximation
//1.27323954 = 4/pi
//0.405284735 =-4/(pi^2)
/*********************************************************
* low precision sine/cosine
*********************************************************/
//always wrap input angle to -PI..PI
if (x < -3.14159265)
x += 6.28318531;