Skip to content

Instantly share code, notes, and snippets.

View amarion35's full-sized avatar

Alexis Marion amarion35

  • BrightClue
  • Rennes, France
  • 10:51 (UTC +02:00)
View GitHub Profile
@amarion35
amarion35 / nested_list_utils.py
Last active May 9, 2019 09:47
Utils to work with nested lists
import numpy as np
from collections.abc import Iterable
import copy
# Find the number of dimensions in a nested list
def find_n_dim(array, depth=0):
if isinstance(array, Iterable):
if len(array)==0:
return depth
return max([find_n_dim(e, depth+1) for e in array])
@amarion35
amarion35 / tt-otaa-UNO.ino
Created December 8, 2018 20:08
LoRa communication UNO+Dragino shield
/*******************************************************************************
* Copyright (c) 2015 Thomas Telkamp and Matthijs Kooijman
*
* Permission is hereby granted, free of charge, to anyone
* obtaining a copy of this document and accompanying files,
* to do whatever they want with them without any restriction,
* including, but not limited to, copying, modification and redistribution.
* NO WARRANTY OF ANY KIND IS PROVIDED.
*
* This example sends a valid LoRaWAN packet with payload "Hello,
@amarion35
amarion35 / tdnn.py
Created October 11, 2018 17:33 — forked from amarioncosmo/tdnn.py
TDNN Layer in Keras
from keras import backend as K
from keras.engine.base_layer import Layer, InputSpec
from keras import activations
from keras.layers.convolutional import _Conv
import numpy as np
class TDNN(_Conv):
# Original TDNN
# A. Waibel, T. Hanazawa, G. Hinton, K. Shikano and K. J. Lang,
# "Phoneme recognition using time-delay neural networks,"
@amarion35
amarion35 / keras_graph_tensorboard.py
Created October 11, 2018 17:33 — forked from amarioncosmo/keras_graph_tensorboard.py
Get a keras model graph in tensorboard
# Launch tensorboard
# $ tensorboard --logdir=~/tensorboard.log
import tensorflow as tf
from keras.layers import Dense, Dropout, Conv3D, MaxPooling3D, GlobalAveragePooling3D
from keras.models import Sequential
import keras.backend as K
model = Sequential()
model.add(Conv3D(8, kernel_size=(3, 3, 3), input_shape=(None,None,None,1), padding='same'))
@amarion35
amarion35 / stdout_plot.py
Created October 11, 2018 17:32 — forked from amarioncosmo/stdout_plot.py
matplotlib is for the weaks
def plot(array, width, height):
size = len(array)
y = [array[int(round(k*size/width)):int(round((k+1)*size/width))] for k in range(width)]
y = [np.mean(k) for k in y[5:]] #y[5:] when the firsts values are too big
y = height*(y-np.min(y))/(np.max(y)-np.min(y))
res = np.array(list([list('#'*int(round(y[k]))+' '*int(round(height-y[k]))) for k in range(len(y))]))
res = np.rot90(res, k=1, axes=(0,1))
for r in res:
print(''.join(r))
#!/usr/bin/python3
import numpy as np
import sys
import time
import math
import os
def plot(array, width, height):
size = len(array)
y = [array[int(round(k*size/width)):int(round((k+1)*size/width))] for k in range(width)]
@amarion35
amarion35 / keras_gpu_options.py
Created October 11, 2018 17:21
Choose your GPU and limit Keras memory usage
import os
os.environ["CUDA_VISIBLE_DEVICES"]="1" #Before all
import tensorflow as tf
config = tf.ConfigProto()
config.gpu_options.allow_growth = True # Use only necessary memory
#config.gpu_options.per_process_gpu_memory_fraction = 0.5
session = tf.Session(config=config) # Before importing Keras!
@amarion35
amarion35 / tt-otaa-M0.ino
Created October 16, 2017 09:16
LoRaWAN communication example
/*******************************************************************************
Copyright (c) 2015 Thomas Telkamp and Matthijs Kooijman
Permission is hereby granted, free of charge, to anyone
obtaining a copy of this document and accompanying files,
to do whatever they want with them without any restriction,
including, but not limited to, copying, modification and redistribution.
NO WARRANTY OF ANY KIND IS PROVIDED.
This example sends a valid LoRaWAN packet with payload "Hello,