View pytorch_tutorial.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View fitting_gaussian.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View num_bins_in_hist.py
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 | |
def _indexer_into(x, dim=0, keepdim=False): | |
'''indexes into x along dim.''' | |
def indexer(i): | |
# (e.g., x[:, 2, :] is indexer(2) if dim == 1) | |
out = x[[slice(None, None)] * dim + [i, ...]] | |
return out.unsqueeze(dim) if keepdim and x.dim() != out.dim() else out | |
return indexer |
View rng.py
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 | |
class RNG(): | |
"""Preserve the state of the random number generators of torch | |
https://gist.github.com/ModarTensai/2328b13bdb11c6309ba449195a6b551a | |
Inspired by torch.random.fork_rng(). | |
Seeding random number generators (RNGs): |
View histogram_summary.py
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 | |
import tensorflow as tf | |
def histogram_summary(name, array): | |
if not hasattr(histogram_summary, 'session'): | |
histogram_summary.placeholder = tf.placeholder(tf.float32) | |
histogram_summary.session = tf.Session() | |
histogram_summary.histograms = {} | |
if name not in histogram_summary.histograms: |
View sfbvc
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
# sfbvc stands for single file branch version control. | |
# | |
# By Modar Alfadly <https://modar.me> on the 24th Jan 2019 | |
# | |
# sfbvc is a convention to create an orphan branch for each file in a repository | |
# and the master branch will be the merge of all the other branches. | |
# This is a niche convention which is trying to simulate file history | |
# in applications similar to cloud storages like Google Drive and Dropbox. | |
# We are using git under the hood and assuming that it is installed and in PATH. | |
# |
View python_cheat_sheet.py
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
#Python Cheat Sheet | |
#Any thing preceded by a '#' is a comment and won't be executed like this line here | |
#Variables are names defined by the programmer that hold values | |
WonderfulVariableByMe = 5 | |
#There are some reserved words like: for, if, def, while, break, ... that cannot be used to name a variable | |
#A variable name must not contain spaces and must never start with a number | |
#Variable names are case-sensitive: modar does not equal Modar |
View running_meters.py
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
"""Seamless running stats for (native python, numpy.ndarray, torch.tensor).""" | |
from collections import namedtuple | |
class MeanMeter: | |
"""Estimate the mean for a stream of values.""" | |
def __init__(self): | |
"""Initialize the meter.""" |
View denormalize_conv2d.py
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 torch.nn import functional as F | |
from torchvision.transforms.functional import normalize | |
def denormalize_conv2d(weight, bias, mean, std): | |
weight, bias = weight.data, bias.data | |
std = torch.as_tensor(std).data.view(1, -1, 1, 1) | |
mean = torch.as_tensor(mean).data.view(1, -1, 1, 1) | |
w = weight / std | |
b = bias - (w * mean).flatten(1).sum(1) |
View polynomial.py
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 | |
def polynomial(coefficients, x): | |
"""Evaluate polynomials using Horner method. | |
The coefficients are from highest to lowest order. | |
Args: | |
coefficients: Tensor of size (N, *K). | |
K is any broadcastable size to `x.size()`. |
OlderNewer