Skip to content

Instantly share code, notes, and snippets.

View Dref360's full-sized avatar

Frédéric Branchaud-Charron Dref360

View GitHub Profile
"""
Simple alarm clock to be awaken to the sound of your choice
"""
import datetime as dt
import time
import webbrowser
import argparse
import sys
from dateutil.relativedelta import relativedelta
@Dref360
Dref360 / DSSIM.py
Last active August 3, 2020 22:43
Difference of stuctural similarity using Tensorflow and keras. Works ONLY on tf >= 0.11
import keras.backend as K
import tensorflow as tf
class Model:
def __init__(self,batch_size):
self.batch_size = batch_size
def loss_DSSIS_tf11(self, y_true, y_pred):
"""Need tf0.11rc to work"""
y_true = tf.reshape(y_true, [self.batch_size] + get_shape(y_pred)[1:])
y_pred = tf.reshape(y_pred, [self.batch_size] + get_shape(y_pred)[1:])
import tensorflow as tf
import numpy as np
import keras
import keras.backend as K
from keras.models import Model
import keras.callbacks as cbks
import threading
from keras.layers import Layer, Input, InputLayer, Dense
@Dref360
Dref360 / TFQueueKeras.py
Last active March 16, 2020 02:24
An example of using keras with tf queues, this handle BatchNorm
import operator
import threading
from functools import reduce
import keras
import keras.backend as K
from keras.engine import Model
import numpy as np
import tensorflow as tf
import time
@Dref360
Dref360 / executor.py
Last active June 6, 2017 20:25
Ordered Multiprocess executor to be used in Keras. (Looks like Pytorch's dataloader)
import os
import time
from concurrent.futures import ProcessPoolExecutor
from itertools import cycle
from queue import Queue
from threading import Thread, Event
from keras.engine.training import GeneratorEnqueuer
import numpy as np
import torch
import torch.nn as nn
import torch.nn.init as init
from torch.autograd import Variable
class Layer(nn.Module):
def __init__(self, in_, out, kernel, init_kernel='uniform', padding=1):
super(Layer, self).__init__()
class weighted_categorical_crossentropy:
def __init__(self, weights):
self.weights = weights
self.__name__ = 'wcentroid_loss'
def __call__(self, y_true, y_pred):
class0 = K.ones_like(y_pred)[:, :, :, 0] * self.weights[0]
class1 = K.ones_like(y_pred)[:, :, :, 0] * self.weights[1]
x = K.tf.where(y_true[:, :, :, 0] > 0, class0, class1)
result = x * K.categorical_crossentropy(y_pred, y_true)
import multiprocessing
import threading
import time
from Queue import Queue
class Sequence():
def __init__(self, my_list):
self.my_list = my_list
import numpy as np
from keras.layers import Input, Lambda
from keras.models import Model
from keras.utils import Sequence
class SSEquence(Sequence):
def __init__(self, value=1):
self.value = value
@Dref360
Dref360 / test_issue.py
Created November 23, 2017 21:59
Test issue multiprocessing
import multiprocessing
import time
import numpy as np
import keras.backend as K
import keras.layers as KL
from keras import Model
from keras.callbacks import Callback
from keras.utils import Sequence