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
| 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")) |
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
| '''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/ |
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 | |
| 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 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.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). |
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
| # 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") |
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.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, |