This file contains 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 numpy as np | |
def slerp(p0, p1, n): | |
# https://en.wikipedia.org/wiki/Slerp | |
norm = np.linalg.norm(p0) * np.linalg.norm(p1) | |
dot = np.sum(p0 * p1 / norm) | |
theta_0 = np.arccos(dot) | |
sin_theta_0 = np.sin(theta_0) | |
interp = [] | |
for t in np.linspace(0.0, 1.0, n): |
This file contains 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 triplet_loss(anchor_embeddings, | |
positive_embeddings, | |
negative_embeddings, | |
margin=0.0): | |
dist_a_p = tf.norm(anchor_embeddings - positive_embeddings, axis=1) # (B) | |
dist_a_n = tf.norm(anchor_embeddings - negative_embeddings, axis=1) # (B) | |
constraint = dist_a_p - dist_a_n + margin # (B) | |
per_element_hinge_loss = tf.maximum(0.0, constraint) # (B) | |
return tf.reduce_mean(per_element_hinge_loss) |
This file contains 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
class EmbeddingModel(keras.Model): | |
def train_step(self, data): | |
anchors, positives = data | |
print("a,p", anchors.shape, positives.shape) | |
with tf.GradientTape() as tape: | |
# Run both anchors and positives through model. | |
anchor_embeddings = self(anchors, training=True) | |
positive_embeddings = self(positives, training=True) |
This file contains 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 numpy as np | |
def rnd(*args): | |
return np.random.random(args) |
This file contains 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
#!/usr/bin/env python3 | |
import argparse | |
import model as m | |
from tensorflow.keras.callbacks import * | |
import data as d | |
import tensorflow as tf | |
import os | |
from lr_finder import LearningRateFinder |
This file contains 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
1/Unknown - 0s 14ms/step | |
--------------------------------------------------------------------------- | |
ValueError Traceback (most recent call last) | |
<ipython-input-2-231b4cfe798d> in <module>() | |
19 dataset = dataset.batch(4).prefetch(1) | |
20 | |
---> 21 model.fit(dataset) | |
/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_freq, max_queue_size, workers, use_multiprocessing, **kwargs) | |
732 max_queue_size=max_queue_size, |
This file contains 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
// set one shot reading | |
register_data = MPL3115A2_CTRL_REG1_OST | | |
MPL3115A2_CTRL_REG1_BAR; | |
Wire.beginTransmission(MPL3115A2_ADDRESS); | |
Wire.write(MPL3115A2_CTRL_REG1); | |
Wire.write(register_data); | |
Wire.endTransmission(true); | |
// wait for one shot bit to auto clear | |
bool ready = false; |
This file contains 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
#include <iostream> | |
#include <thread> | |
using namespace std; | |
using namespace std::chrono; | |
// do all operations in milliseconds | |
int main(int argc, char *argv[]) { | |
This file contains 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
#!/usr/bin/env python3 | |
from tensorflow.keras import models | |
from tensorflow.keras import layers | |
inp = layers.Input(shape=(1,)) | |
out = layers.ReLU()(inp) | |
model = models.Model(inp, out) | |
model.compile(loss='mean_squared_error', optimizer='sgd') |
This file contains 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
#!/usr/bin/env python3 | |
from tensorflow.keras import models | |
from tensorflow.keras import layers | |
inp = layers.Input(shape=(1,)) | |
out = layers.Activation('relu')(inp) | |
model = models.Model(inp, out) |
NewerOlder