Skip to content

Instantly share code, notes, and snippets.

View radi-cho's full-sized avatar

Radi Cho radi-cho

View GitHub Profile
v_channels = tf.linalg.matrix_transpose(v)
v_projected = self.spatial_projection(v_channels)
v_projected = tf.linalg.matrix_transpose(v_projected)
self.spatial_projection = layers.Dense(units=num_patches, bias_initializer="Ones")
def spatial_gating_unit(self, x):
# u and v shape: [batch_size, num_patchs, embedding_dim]
u, v = tf.split(x, num_or_size_splits=2, axis=2)
v = self.normalize2(v)
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
class gMLPLayer(layers.Layer):
def __init__(self, num_patches, embedding_dim, dropout_rate, *args, **kwargs):
super(gMLPLayer, self).__init__(*args, **kwargs)
self.normalize1 = layers.LayerNormalization(epsilon=1e-6)
self.normalize2 = layers.LayerNormalization(epsilon=1e-6)
self.channel_projection1 = keras.Sequential(
[
layers.Dense(units=embedding_dim * 2),
layers.ReLU(),
layers.Dropout(rate=dropout_rate),
]
)
tf.one_hot(tf.argmax(p), depth = len(p))
<tf.Tensor: shape=(3,), dtype=float32, numpy=array([0., 1., 0.], dtype=float32)>
temperature = 0.01
dist = tfp.distributions.RelaxedOneHotCategorical(temperature, probs=p)
dist.sample()
<tf.Tensor: shape=(3,), dtype=float32, numpy=array([0., 1., 0.], dtype=float32)>
temperature = 10
dist = tfp.distributions.RelaxedOneHotCategorical(temperature, probs=p)
dist.sample()
<tf.Tensor: shape=(3,), dtype=float32, numpy=array([0.31916314, 0.34642866, 0.33440822], dtype=float32)>
@radi-cho
radi-cho / safeStringify.js
Created May 6, 2020 09:17
JSON.safeStringify method
JSON.safeStringify = (obj, indent = 2) => {
let cache = [];
const retVal = JSON.stringify(
obj,
(key, value) =>
typeof value === "object" && value !== null
? cache.includes(value)
? undefined // Duplicate reference found, discard key
: cache.push(value) && value // Store value in our collection
: value,
@radi-cho
radi-cho / proguard-user.txt
Created February 5, 2019 09:30
Proguard config for solving the common Admob Unity error ClassNotFoundException ads.UnityAdListener
-keep class com.google.unity.** {
*;
}
-keep public class com.google.android.gms.ads.**{
public *;
}
-keep public class com.google.ads.**{
public *;
}
-keepattributes *Annotation*