Skip to content

Instantly share code, notes, and snippets.

View shangeth's full-sized avatar
🏠
Working from home

Shangeth shangeth

🏠
Working from home
View GitHub Profile
@shangeth
shangeth / download_common_voice_16.py
Created March 6, 2024 02:27
This Python script automates downloading and extracting .tar files from the Common Voice dataset on Hugging Face, using a Hugging Face token for authorization. It creates directories based on set types (e.g., "test"), downloads specified .tar files, extracts their contents, and cleans up by removing the .tar files post-extraction. Ideal for res…
import requests
import os
import tarfile
# Hugging Face token
hf_token = "<HF_TOKEN_HERE>"
headers = {"Authorization": f"Bearer {hf_token}"}
# Directory to save and extract files
@shangeth
shangeth / dl_drl_projects.md
Last active November 8, 2019 19:29
List of projects worked on by shangeth(shangeth.com) on Deep Reinforcement Learning
X = np.random.rand(3,3)
print('Input X = \n',X)
w = np.random.normal(loc=0.0, scale=0.01, size=(3,1))
print('\nInitialized weight w = \n',w)
bias = np.ones((3,1))
print('\nInitialized bias b = \n',bias)
z = np.dot(X, w) + bias z
import torch
x = np.random.randn(3,3)
x_tensor = torch.from_numpy(x)
dropout = torch.nn.Dropout(0.5)
dropout(x_tensor)
def dropout(X, drop_probability):
keep_probability = 1 - drop_probability
mask = np.random.uniform(0, 1.0, X.shape) < keep_probability
if keep_probability > 0.0:
scale = (1/keep_probability)
else:
scale = 0.0
return mask * X * scale
import random
from scipy import ndarray
import skimage as sk
from skimage import transform
from skimage import util
def random_rotation(image_array: ndarray):
random_degree = random.uniform(-25, 25)
return sk.transform.rotate(image_array, random_degree)
from skimage import io
import matplotlib.pyplot as plt
image = io.imread('https://cdn3.bigcommerce.com/s-nadnq/product_images/uploaded_images/20.jpg')
plt.imshow(image)
plt.grid(False)
plt.axis('off')
plt.show()
x = torch.randn(1, 3, 224, 224).uniform_(0, 1)
alexnet = AlexNet()
alexnet(x).size()
class AlexNet(nn.Module):
def __init__(self, classes=1000):
super(AlexNet, self).__init__()
self.features = nn.Sequential(
nn.Conv2d(3, 64, kernel_size=11, stride=4, padding=2),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3, stride=2),
nn.Conv2d(64, 192, kernel_size=5, padding=2),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3, stride=2),
@shangeth
shangeth / lrn.py
Last active December 27, 2018 05:54
import torch.nn as nn
class LRN(nn.Module):
def __init__(self, size, alpha=1e-4, beta=0.75, k=1):
super(LRN, self).__init__()
self.avg = nn.AvgPool3d(kernel_size =(size,1,1), stride=1, padding=int((size-1)/2))
self.alpha = alpha
self.beta = beta
self.k = k