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
client = boto3.client('ec2') | |
instance_id = 'my instance id' | |
def rotate_ip(last_eip=None): | |
if last_eip: | |
client.release_address(AllocationId=last_eip['AllocationId']) | |
eip = client.allocate_address(Domain='vpc') | |
r = client.associate_address(AllocationId=eip['AllocationId'], InstanceId=instance_id) | |
return eip |
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
# modified from http://scikit-image.org/docs/stable/auto_examples/transform/plot_pyramid.html#sphx-glr-auto-examples-transform-plot-pyramid-py | |
import numpy as np | |
import matplotlib.pyplot as plt | |
from skimage import data | |
from skimage.transform import pyramid_gaussian | |
image = data.astronaut() |
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
%matplotlib inline | |
import matplotlib.pyplot as plt | |
import matplotlib.patches as mpatches | |
from skimage import data | |
# get image | |
img = data.astronaut() | |
print('image size', img.shape) | |
fig, ax = plt.subplots() | |
ax.imshow(img) |
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
%matplotlib inline | |
import numpy as np | |
import matplotlib.pyplot as plt | |
from skimage.draw import (line, polygon, circle, | |
circle_perimeter, | |
ellipse, ellipse_perimeter, | |
bezier_curve) | |
# Draw a rectangle | |
img = np.ones((10, 10), dtype=np.double) # a gray image |
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 Pair: | |
def __init__(self, key, value): | |
self.key = key | |
self.value = value | |
def __str__(self): | |
return "({}, {})".format(str(self.key), str(self.value)) | |
def __repr__(self): | |
return self.__str__() |
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
#include <stdio.h> | |
void deviceQuery () | |
{ | |
cudaDeviceProp prop; | |
int nDevices=0, i; | |
cudaError_t ierr; | |
ierr = cudaGetDeviceCount(&nDevices); |
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
#include <stdio.h> | |
#define N (32) | |
__global__ void increment(int* time) { | |
__shared__ float s[1024]; | |
for (int i = 0; i < 1024; i++) { | |
s[i] = 1.0f; | |
} |
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 datetime import datetime | |
import json | |
class Timer: | |
def __init__(self, outputFile): | |
self.fout = open(outputFile, 'w') | |
self.cache = [] | |
self.records = {} | |
def start(self, event="time"): |
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 | |
def compute_average_precision(test_results, num_true_cases): | |
""" | |
It computes average precision based on the definition of Pascal Competition. It computes the under curve area | |
of precision and recall. Recall follows the normal definition. Precision is a variant. | |
pascal_precision[i] = typical_precision[i:].max() | |
Usage: | |
test_results = np.array([True, False, True, False, True, False, False, False, False, True]) |
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
r"""Convert an ImageNet like dataset into tfRecord files, provide a method get_dataset to read the created files. | |
It has similar functions as ImageFolder in Pytorch. | |
Modified from | |
https://raw.githubusercontent.com/tensorflow/models/master/research/slim/datasets/download_and_convert_flowers.py | |
https://github.com/tensorflow/models/blob/master/research/slim/datasets/flowers.py | |
""" | |
from __future__ import absolute_import |
OlderNewer