深度学习零基础?没关系——面向艺术家的RNN教程

+关注继续查看

Github地址：https://github.com/hardmaru

var x, y; // absolute coordinates of where the pen is
var dx, dy; // offsets of the pen strokes, in pixels

// keep track of whether pen is touching paper. 0 or 1.
var pen;
var prev_pen; // pen at the previous timestep

var rnn_state; // store the hidden states the rnn

// store all the parameters of a mixture-density distribution
var pdf;

// controls the amount of uncertainty of the model
// the higher the temperature, the more uncertainty.
var temperature = 0.65; // a non-negative number.

rnn_state 变量代表RNN的隐藏状态使用代码update更新rnn_state

rnn_state = Model.update([dx, dy, prev_pen], rnn_state);

rnn_state将用产生模型将要写内容的概率分布。该概率分布表示作为主体，称作pdf。使用get_pdf就能rnn_state获得pdf

pdf = Model.get_pdf(rnn_state);

额外变量temperature使我们能够控制该模型是否为想要的模型。结合pdf可以使用 sample函数去采样下一组(dx, dy, pen)在稍后使用以下函数：

[dx, dy, pen] = Model.sample(pdf, temperature);

// stores the browser's dimensions
var screen_width = window.innerWidth;
var screen_height = window.innerHeight;

// colour for the handwriting
var line_color;

function restart() {
// set x to be 50 pixels from the left of the canvas
x = 50;
// set y somewhere in middle of the canvas
y = screen_height/2;

// initialize pen's states to zero.
dx = 0;
dy = 0;
prev_pen = 0;
// note: we draw lines based off previous pen's state

// randomise the rnn's initial hidden states
rnn_state = Model.random_state();

// randomise colour of line by choosing RGB values
line_color = color(random(255), random(255), random(255))
}

function setup() {
restart(); // initialize variables for this demo
createCanvas(screen_width, screen_height);
frameRate(60); // 60 frames per second
// clear the background to be blank white colour
background(255);
fill(255);
}

p5.j s框架中的 draw函数能够产生一代手写字迹，该函数每秒调用60每次调用此函数时，RNN将在屏幕上绘制一些东西。

function draw() {

// using the previous pen states, and hidden state
// to get next hidden state
rnn_state = Model.update([dx, dy, prev_pen], rnn_state);

// get the parameters of the probability distribution
// from the hidden state
pdf = Model.get_pdf(rnn_state);

// sample the next pen's states
// using our probability distribution and temperature
[dx, dy, pen] = Model.sample(pdf, temperature);

// only draw on the paper if pen is touching the paper
if (prev_pen == 0) {
// set colour of the line
stroke(line_color);
// set width of the line to 2 pixels
strokeWeight(2.0);
// draw line connecting prev point to current point.
line(x, y, x+dx, y+dy);
}

// update the absolute coordinates from the offsets
x += dx;
y += dy;

// update the previous pen's state
// to the current one we just sampled
prev_pen = pen;

// if the rnn starts drawing close to the right side
// of the screen, restart our demo
if (x > screen_width - 50) {
restart();
// reset screen
background(255);
fill(255);
}

}

数十款阿里云产品限时折扣中，赶紧点击领劵开始云上实践吧！

本文由北邮@爱可可-爱生活 老师推荐，阿里云云栖社区组织翻译。

文章原标题《Recurrent Neural Network Tutorial for Artists》，作者：hardmaru ，译者：海棠

文章为简译，更为详细的内容，请查看原文

Python零基础学习笔记（五）—— 标识符

1427 0
Python零基础学习笔记（六）—— 变量和常量

1373 0
Jenkins 教程（二）实现本地资源ssh上传

862 0

873 0
Directx11教程(45) alpha blend(2)

682 0
Directx11教程(47) alpha blend(4)-雾的实现

709 0

1092 0

976 0
Python零基础学习笔记（十七）—— for 语句
''' for 语句,是一种循环语句 格式： for 变量名 in 集合： 语句 逻辑：按顺序取“集合”中的每个元素赋值给“变量”，再去执行语句 如此循环往复，直到取玩“集合”中的元素为止 ''' for i in [1,2,3,4,5]: print(i) '...
1159 0
+关注
【方向】

696

5

《SaaS模式云原生数据仓库应用场景实践》

《看见新力量：二》电子书