Skip to content

Instantly share code, notes, and snippets.

@kevinzakka
kevinzakka / spatial_softmax.py
Last active November 6, 2024 10:31
Pytorch Spatial Soft Argmax
import torch
import torch.nn as nn
import torch.nn.functional as F
class SpatialSoftArgmax(nn.Module):
"""Spatial softmax as defined in [1].
Concretely, the spatial softmax of each feature
map is used to compute a weighted mean of the pixel
@williamFalcon
williamFalcon / Pytorch_LSTM_variable_mini_batches.py
Last active April 24, 2024 17:53
Simple batched PyTorch LSTM
import torch
import torch.nn as nn
from torch.autograd import Variable
from torch.nn import functional as F
"""
Blog post:
Taming LSTMs: Variable-sized mini-batches and why PyTorch is good for your health:
https://medium.com/@_willfalcon/taming-lstms-variable-sized-mini-batches-and-why-pytorch-is-good-for-your-health-61d35642972e
"""
@khanhnamle1994
khanhnamle1994 / main.py
Last active March 2, 2025 05:25
FCN - Full Code
#--------------------------
# USER-SPECIFIED DATA
#--------------------------
# Tune these parameters
num_classes = 2
image_shape = (160, 576)
EPOCHS = 40
BATCH_SIZE = 16
@tokestermw
tokestermw / birnnlm_pytorch.py
Last active May 30, 2020 08:29
Simple example of Bidirectional RNN Language Model in PyTorch. (blog post: https://medium.com/@plusepsilon/the-bidirectional-language-model-1f3961d1fb27)
import torch, torch.nn as nn
from torch.autograd import Variable
text = ['BOS', 'How', 'are', 'you', 'EOS']
seq_len = len(text)
batch_size = 1
embedding_size = 1
hidden_size = 1
output_size = 1
@ceshine
ceshine / birnn.ipynb
Created November 12, 2017 08:52
Figuring How Bidirectional RNN works in Pytorch
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@hiwonjoon
hiwonjoon / q_learning_v1.py
Created June 19, 2017 04:26
Q-learning algorithm for OpenAI Gym CartPole-v1
import numpy as np
import sys
import random
import tensorflow as tf
import itertools
slim = tf.contrib.slim
BATCH_SIZE = 32
TRAIN_ITER = 1000
EARLY_TRAIN_TERMINATE_CRITERIA = 1e-3;
@spro
spro / pytorch-simple-rnn.py
Last active November 7, 2024 11:24
PyTorch RNN training example
import torch
import torch.nn as nn
from torch.nn import functional as F
from torch.autograd import Variable
from torch import optim
import numpy as np
import math, random
# Generating a noisy multi-sin wave
@shamatar
shamatar / rwa.py
Last active January 14, 2022 20:17
Keras (keras.is) implementation of Recurrent Weighted Average, as described in https://arxiv.org/abs/1703.01253. Follows original implementation in Tensorflow from https://github.com/jostmey/rwa. Works with fixed batch sizes, requires "batch_shape" parameter in input layer. Outputs proper config, should save and restore properly. You are welcome…
from keras.layers import Recurrent
import keras.backend as K
from keras import activations
from keras import initializers
from keras import regularizers
from keras import constraints
from keras.engine import Layer
from keras.engine import InputSpec
@awjuliani
awjuliani / Q-Net Learning Clean.ipynb
Created August 25, 2016 20:30
Basic Q-Learning algorithm using Tensorflow
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@awjuliani
awjuliani / Q-Table Learning-Clean.ipynb
Last active October 25, 2022 07:57
Q-Table learning in OpenAI grid world.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.