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 numpy as np | |
from torch import nn | |
import torch.nn.functional as F | |
H=4;W=3 | |
pad = 1 | |
stride=2 | |
kernel_size = 3 |
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 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 |
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
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()) |
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 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) |
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 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: |
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
# 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): |
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
\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} |
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
# 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: |
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
''' | |
ddpg | |
''' | |
import tensorflow as tf | |
import numpy as np | |
import gym |
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
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] |
NewerOlder