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 import layers | |
def residual_block(y, nb_channels, _strides=(1, 1), _project_shortcut=False): | |
shortcut = y | |
# down-sampling is performed with a stride of 2 | |
y = layers.Conv2D(nb_channels, kernel_size=(3, 3), strides=_strides, padding='same')(y) | |
y = layers.BatchNormalization()(y) | |
y = layers.LeakyReLU()(y) |
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 torch | |
from torch import autograd | |
from torch import nn | |
class CrossEntropyLoss(nn.Module): | |
""" | |
This criterion (`CrossEntropyLoss`) combines `LogSoftMax` and `NLLLoss` in one single class. | |
NOTE: Computes per-element losses for a mini-batch (instead of the average loss over the entire mini-batch). |
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 torch | |
from torch.autograd import Variable | |
import torch.nn as nn | |
class Bottleneck(nn.Module): | |
cardinality = 32 # the size of the set of transformations | |
def __init__(self, nb_channels_in, nb_channels, nb_channels_out, stride=1): | |
super().__init__() |
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
# http://www.nvidia.com/download/driverResults.aspx/117079/en-us | |
wget http://us.download.nvidia.com/tesla/375.51/nvidia-driver-local-repo-ubuntu1604_375.51-1_amd64.deb | |
sudo dpkg -i nvidia-driver-local-repo-ubuntu1604_375.51-1_amd64.deb | |
sudo apt-get update | |
sudo apt-get -y install cuda-drivers | |
echo "Reboot required." |
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
#!/bin/bash | |
# install CUDA Toolkit v8.0 | |
# instructions from https://developer.nvidia.com/cuda-downloads (linux -> x86_64 -> Ubuntu -> 16.04 -> deb (network)) | |
CUDA_REPO_PKG="cuda-repo-ubuntu1604_8.0.61-1_amd64.deb" | |
wget http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/${CUDA_REPO_PKG} | |
sudo dpkg -i ${CUDA_REPO_PKG} | |
sudo apt-get update | |
sudo apt-get -y install cuda |
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 io | |
from PIL import Image # https://pillow.readthedocs.io/en/4.3.x/ | |
import requests # http://docs.python-requests.org/en/master/ | |
# example image url: https://m.media-amazon.com/images/S/aplus-media/vc/6a9569ab-cb8e-46d9-8aea-a7022e58c74a.jpg | |
def download_image(url, image_file_path): | |
r = requests.get(url, timeout=4.0) | |
if r.status_code != requests.codes.ok: |
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
""" | |
Clean and simple Keras implementation of network architectures described in: | |
- (ResNet-50) [Deep Residual Learning for Image Recognition](https://arxiv.org/pdf/1512.03385.pdf). | |
- (ResNeXt-50 32x4d) [Aggregated Residual Transformations for Deep Neural Networks](https://arxiv.org/pdf/1611.05431.pdf). | |
Python 3. | |
""" | |
from keras import layers | |
from keras import models |
OlderNewer