Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
!pip install fastai | |
!apt-get -qq install -y libsm6 libxext6 && pip install -q -U opencv-python | |
import cv2 | |
from os import path | |
from wheel.pep425tags import get_abbr_impl, get_impl_ver, get_abi_tag | |
platform = '{}{}-{}'.format(get_abbr_impl(), get_impl_ver(), get_abi_tag()) | |
accelerator = 'cu80' if path.exists('/opt/bin/nvidia-smi') else 'cpu' | |
!pip install -q http://download.pytorch.org/whl/{accelerator}/torch-0.3.0.post4-{platform}-linux_x86_64.whl torchvision |
This file contains 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
class LearningRateFinder(Callback): | |
''' | |
This callback implements a learning rate finder(LRF) | |
The learning rate is constantly increased during training. | |
On training end, the training loss is plotted against the learning rate. | |
One may choose a learning rate for a model based on the given graph, | |
selecting a value slightly before the minimal training loss. | |
# Example | |
lrf = LearningRateFinder([0.0001, 0.0005, 0.001, 0.005, 0.01, 0.05]) | |
model.fit(x_train, y_train, epochs=1, batch_size=128, callbacks=[lrf]) |
This file contains 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 keras import backend as K | |
from keras.preprocessing.image import Iterator, load_img, img_to_array | |
class FileListIterator(Iterator): | |
"""Iterator capable of reading images from an array of the filenames. | |
# Arguments | |
filenames: Path to the directory to read images from. | |
Each subdirectory in this directory will be | |
considered to contain images from one class, |
This file contains 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, |
This file contains 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.layers import Conv2D | |
from keras.layers import Activation | |
from keras.layers import Add | |
from keras.layers import BatchNormalization | |
from keras.layers import ZeroPadding2D | |
from keras.layers import MaxPooling2D | |
def identity_block(input_tensor, kernel_size, filters, stage, block, use_bias=True): | |
""" | |
This block is the one with no convolutional layer at its shortcut branch |
This file contains 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/ | |
- created cats/ and dogs/ subfolders inside train/ and validation/ | |
- put the cat pictures index 0-999 in data/train/cats |
The prep-script.sh
will setup the latest Node and install the latest perf version on your Linux box.
When you want to generate the flame graph, run the following (folder locations taken from install script):
sudo sysctl kernel.kptr_restrict=0
# May also have to do the following:
# (additional reading http://unix.stackexchange.com/questions/14227/do-i-need-root-admin-permissions-to-run-userspace-perf-tool-perf-events-ar )
sudo sysctl kernel.perf_event_paranoid=0