Skip to content

Instantly share code, notes, and snippets.

@juanlp
juanlp / sgdr.py
Created September 23, 2018 05:30 — forked from jeremyjordan/sgdr.py
Keras Callback for implementing Stochastic Gradient Descent with Restarts
from keras.callbacks import Callback
import keras.backend as K
import numpy as np
class SGDRScheduler(Callback):
'''Cosine annealing learning rate scheduler with periodic restarts.
# Usage
```python
schedule = SGDRScheduler(min_lr=1e-5,
@juanlp
juanlp / convert_weights.py
Created August 28, 2018 13:15 — forked from hollance/convert_weights.py
SE-ResNet-50 in Keras
# Convert SE-ResNet-50 from Caffe to Keras
# Using the model from https://github.com/shicai/SENet-Caffe
import os
import numpy as np
# The caffe module needs to be on the Python path; we'll add it here explicitly.
import sys
caffe_root = "/path/to/caffe"
sys.path.insert(0, caffe_root + "python")
@juanlp
juanlp / keras-resnet-extract-bottleneck-features.py
Created February 2, 2017 13:40 — forked from okiriza/keras-resnet-extract-bottleneck-features.py
Python function for extracting image features using bottleneck layer of Keras' ResNet50
from keras.applications.resnet50 import ResNet50, preprocess_input
from keras.preprocessing import image
import numpy as np
resnet = ResNet50(include_top=False)
def extract_features(img_paths, batch_size=64):
""" This function extracts image features for each image in img_paths using ResNet50 bottleneck layer.
Returned features is a numpy array with shape (len(img_paths), 2048).
@juanlp
juanlp / elastic_transform.py
Created July 10, 2016 10:44 — forked from fmder/elastic_transform.py
Elastic transformation of an image in Python
import numpy
from scipy.ndimage.interpolation import map_coordinates
from scipy.ndimage.filters import gaussian_filter
def elastic_transform(image, alpha, sigma, random_state=None):
"""Elastic deformation of images as described in [Simard2003]_.
.. [Simard2003] Simard, Steinkraus and Platt, "Best Practices for
Convolutional Neural Networks applied to Visual Document Analysis", in
'''This script goes along the blog post
"Building powerful image classification models using very little data"
from blog.keras.io.
It uses data that can be downloaded at:
https://www.kaggle.com/c/dogs-vs-cats/data
In our setup, we:
- created a data/ folder
- created train/ and validation/ subfolders inside data/
@juanlp
juanlp / server.R
Created October 15, 2015 01:14 — forked from trestletech/server.R
A Shiny app combining the use of dplyr and SQLite. The goal is to demonstrate a full-fledged, database-backed user authorization framework in Shiny.
library(shiny)
library(dplyr)
library(lubridate)
# Load libraries and functions needed to create SQLite databases.
library(RSQLite)
library(RSQLite.extfuns)
saveSQLite <- function(data, name){
path <- dplyr:::db_location(filename=paste0(name, ".sqlite"))