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 torch | |
| import torch.nn as nn | |
| def compute_scale_and_shift(prediction, target, mask): | |
| # system matrix: A = [[a_00, a_01], [a_10, a_11]] | |
| a_00 = torch.sum(mask * prediction * prediction, (1, 2)) | |
| a_01 = torch.sum(mask * prediction, (1, 2)) | |
| a_11 = torch.sum(mask, (1, 2)) |
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 will demonstrate how to use a pretrained model, in PyTorch, | |
| to make predictions. Specifically, we will be using VGG16 with a cat | |
| image. | |
| References used to make this script: | |
| PyTorch pretrained models doc: | |
| http://pytorch.org/docs/master/torchvision/models.html | |
| PyTorch image transforms example: | |
| http://pytorch.org/tutorials/beginner/data_loading_tutorial.html#transforms |
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 as np | |
| class KernelDensity: | |
| def __init__(self, kernel='gaussian', bandwidth=0.2): | |
| self.kernel_ = kernel | |
| self.bandwidth_ = bandwidth | |
| def fit(self, X): | |
| self.X_ = X | |
| self.n_ = X.shape[0] |
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 matplotlib.pyplot as plt | |
| import numpy as np | |
| def show_images(images, cols = 1, titles = None): | |
| """Display a list of images in a single figure with matplotlib. | |
| Parameters | |
| --------- | |
| images: List of np.arrays compatible with plt.imshow. | |
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 sklearn.decomposition import PCA | |
| import matplotlib.pyplot as plt | |
| from sklearn import datasets | |
| iris = datasets.load_iris() | |
| X = iris.data | |
| model = PCA() | |
| model.fit(X) |
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
| user@server$ jupyter notebook --no-browser --port=8889 | |
| # run client side | |
| user@client$ ssh -N -f -L localhost:8000:localhost:8889 remote_user@remote_host | |
| firefox http://localhost:8000 | |
| # source: https://coderwall.com/p/ohk6cg/remote-access-to-ipython-notebooks-via-ssh |
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
| #ifndef RANGE_HPP_ | |
| #define RANGE_HPP_ | |
| template<typename T> class RangeIterator; | |
| template<typename T> | |
| class Range | |
| { | |
| T _start, _end, _step; |