Skip to content

Instantly share code, notes, and snippets.

View mohamad-hasan-sohan-ajini's full-sized avatar

mohammad hasan sohan ajini mohamad-hasan-sohan-ajini

View GitHub Profile
@karpathy
karpathy / pg-pong.py
Created May 30, 2016 22:50
Training a Neural Network ATARI Pong agent with Policy Gradients from raw pixels
""" Trains an agent with (stochastic) Policy Gradients on Pong. Uses OpenAI Gym. """
import numpy as np
import cPickle as pickle
import gym
# hyperparameters
H = 200 # number of hidden layer neurons
batch_size = 10 # every how many episodes to do a param update?
learning_rate = 1e-4
gamma = 0.99 # discount factor for reward
@nailo2c
nailo2c / pytorch-policy-gradient.py
Last active March 25, 2019 08:27
Implement policy gradient by PyTorch and training on ATARI Pong
# -*- coding: utf-8 -*-
import os
import argparse
import gym
import numpy as np
from itertools import count
import torch
import torch.nn as nn
@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
import torch
import torch.nn as nn
import torch.optim as optim
from torch.autograd import Variable
import torch.nn.functional as F
import matplotlib.pyplot as plt
import numpy as np
@IdeaKing
IdeaKing / resize_with_pad_cv2.py
Last active February 1, 2024 16:18
Resize image with padding using CV2
import cv2
from typing import Tuple
def resize_with_pad(image: np.array,
new_shape: Tuple[int, int],
padding_color: Tuple[int] = (255, 255, 255)) -> np.array:
"""Maintains aspect ratio and resizes with padding.
Params:
image: Image to be resized.