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
// Call like below | |
// boxedMat will contain resized image | |
// boxedMat = __LetterBoxResize(floatMat, net->w, net->h); | |
// | |
// Taken mostly from https://jdhao.github.io/2017/11/06/resize-image-to-square-with-padding/ | |
cv::Mat ArapahoV2::__LetterBoxResize(cv::Mat img, int w, int h) | |
{ | |
cv::Mat intermediateImg, outputImg; | |
int delta_w, delta_h, top, left, bottom, right; |
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
# -*- coding: utf-8 -*- | |
""" | |
Created on Mon Jun 13 16:59:53 2016 | |
From - https://stats.stackexchange.com/questions/218407/encoding-angle-data-for-neural-network | |
@author: Ari | |
""" | |
from numpy import savetxt, loadtxt, round, zeros, sin, cos, arctan2, clip, pi, tanh, exp, arange, dot, outer, array, shape, zeros_like, reshape, mean, median, max, min | |
from numpy.random import rand, shuffle | |
import matplotlib.pyplot as plt |
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 os | |
import json | |
def path_to_dict(path): | |
d = {'name': os.path.basename(path)} | |
if os.path.isdir(path): | |
d['type'] = "directory" | |
d['children'] = [path_to_dict(os.path.join(path,x)) for x in os.listdir\ | |
(path)] | |
else: |
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
# https://stackoverflow.com/questions/56069411 | |
# The TF code | |
score_inputs = tf.placeholder(np.float32, shape=(None, 100)) | |
targets = tf.placeholder(np.float32, shape=(None), name="targets") | |
l2 = tf.contrib.layers.l2_regularizer(0.01) | |
first_layer = tf.layers.dense(score_inputs, 100, activation=tf.nn.relu, kernel_regularizer=l2) | |
outputs = tf.layers.dense(first_layer, 1, activation = None, kernel_regularizer=l2) |
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 keras.models import Sequential | |
from keras.layers import Dense | |
import numpy as np | |
def normalize_angles(phases): | |
phases = phases + np.pi | |
phases /= (2 * np.pi) | |
return phases | |
def build_fourier_mnist(): |
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
CuDNNGRU stateful implementation, TensorFlow backend | |
Layers: (300,80,150) -- (encoder, latent, decoder) -- (selu, tanh, tanh) | |
return_sequences=True for all layers | |
GaussianNoise + Dropout at (=after) input, AlphaDropout at encoder, Dropout at latent | |
BatchNormalization between encoder and latent, latent and decoder | |
Output: TimeDistributed(Dense(units=input_dim, activation='linear')) | |
batch_size=25, timesteps=400, input_dim=16 - 25 separate, 10-min sequences fed 400 timesteps (=1 sec) at a time (as 10*60=600 'windows' in parallel, non-shuffled) | |
reset_states() applied before testing on new x25 10-min sequences | |
model.fit, or train_on_batch for training |
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 keras.datasets import mnist | |
from keras.layers import Dense, Input, concatenate,subtract, Lambda | |
from keras.losses import binary_crossentropy | |
from keras.optimizers import SGD | |
(train_x, train_y), (test_x, test_y) = mnist.load_data() | |
train_x = (train_x / 255.0).reshape(-1, 28*28) | |
test_x = (test_x / 255.0).reshape(-1, 28*28) | |
inp1 = Input(shape=(28*28,)) |
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 numpy as np | |
from numpy.lib.stride_tricks import as_strided | |
import tensorflow as tf | |
import time | |
def conv2dTrickster(a, b): | |
a = as_strided(a,(len(a),a.shape[1]-len(b)+1,a.shape[2]-b.shape[1]+1,len(b),b.shape[1],a.shape[3]),a.strides[:3]+a.strides[1:]) | |
return np.einsum('abcijk,ijkd', a, b[::-1,::-1]) | |
def conv2dSimple(image, filter): |
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
# conv1d for timeseries spike | |
model = models.Sequential() | |
model.add(layers.Conv1D(filters = 1, | |
kernel_size = 10, | |
activation = 'relu', | |
input_shape=(timesteps,1))) | |
model.add(layers.GlobalMaxPooling1D()) | |
model.add(layers.Flatten()) | |
model.add(layers.Dense(1, activation = 'sigmoid')) |
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
$ diff ~/Downloads/yolov3.cfg-master.txt ~/Downloads/yolov3.cfg-alexeyab.txt | |
3,4c3,4 | |
< # batch=1 | |
< # subdivisions=1 | |
--- | |
> batch=1 | |
> subdivisions=1 | |
6,9c6,9 | |
< batch=64 | |
< subdivisions=16 |