Skip to content

Instantly share code, notes, and snippets.

View hccho2's full-sized avatar

Heecheol Cho hccho2

View GitHub Profile
import torch
import numpy as np
from torch import nn
import torch.nn.functional as F
H=4;W=3
pad = 1
stride=2
kernel_size = 3
import numpy as np
import tensorflow as tf
import torch
print(f'Tensorflow Version: {tf.__version__}')
HCCHO = True # cn231n code에서 im2col의 2-dim의 행벡터가 batch data가 섞여서 나오는 방식이라, 이를 batch data간에 섞이지 않는 방식으로 변환.
def get_im2col_indices(x_shape, field_height, field_width, padding=1, stride=1):
# First figure out what the size of the output should be
lr = 0.1
model = nn.Linear(10,1)
optimizer = torch.optim.Adam(model.parameters(), lr=lr)
lambda1 = lambda epoch: epoch/10 # lr * lambda1(epoch+1)
scheduler = torch.optim.lr_scheduler.LambdaLR(optimizer,lambda1)
print(optimizer.state_dict())
from PIL import ImageTk, Image, ImageDraw
import PIL
from tkinter import *
import os
width = 200
height = 200
center = height//2
white = (255, 255, 255)
black = (0,0,0)
green = (0,128,0)
@hccho2
hccho2 / torch_data.py
Last active November 29, 2020 01:31
torch data
import torch
import numpy as np
x = torch.Tensor([[100],[200]])
y = init.uniform_(x,-5,5) # x의 값을 변경 --> return 되는 것은 alias
w = x.detach()
print(x,y,w) # x,y는 같은 객체
a = np.array([[2],[1.]])
case = 2
if case==1:
# waveform = torch.from_numpy(waveform) ----> numpy array를 torch tensor로 변환하는 것은 속도에 영향이 거의 없다.
# sr = 22050이면 --> torchaudio가 많이 느리다.
# sr = 16000 ---> origin sample_rate과 일치하면 모두 다 빠르다.
# sr = 8000
n_samples = 100
sr = 22050
s_time=time.time()
for i in range(n_samples):
\documentclass[]{article}
\usepackage[margin=1cm]{geometry}
\usepackage{tikz,pgfplots,pgf}
\usepackage{neuralnetwork}
\usepackage{sidecap}
\usepackage{amsmath}
\usetikzlibrary{matrix,shapes,arrows,positioning}
\usetikzlibrary{chains,decorations.pathreplacing}
\usetikzlibrary{backgrounds}
@hccho2
hccho2 / batch_to_seq.py
Created March 30, 2020 23:21
batch_to_seq & seq _to_batch
# remove last step
def strip(var, nenvs, nsteps, flat = False):
# var: [ nenvs*(nsteps+1), last_dim]
last_dim = var.get_shape()[-1].value
vars = batch_to_seq(var, nenvs, nsteps + 1, flat) # var: (nenvs,last_dim) ---> list of length nsteps+1
# vars: [(nenvs,last_dim), (nenvs,last_dim), .... ] <----- nsteps+1 길이
return seq_to_batch(vars[:-1],last_dim, flat)
def batch_to_seq(h, nbatch, nsteps, flat=False):
if flat:
@hccho2
hccho2 / pendulum-ddpg
Last active March 6, 2020 06:38
pendulum-ddpg
'''
ddpg
'''
import tensorflow as tf
import numpy as np
import gym
x = np.array([[0.49593696, 0.504063 ],
[0.4912244 , 0.50877565],
[0.48871803, 0.51128197],
[0.48469874, 0.5153013 ],
[0.4801116 , 0.5198884 ]])
a = np.array([0,0,1,1,0]).astype(np.int32)
# numpy array
Z = x[range(5),a]