接着须要定义 timestep ,可见层和隐蔽层的大年夜小。
4.更新变量:
- size_bt = tf. CA
- st(tf.shape(x)[0], tf.float32)
- W_adder = tf.mul(lr/size_bt, tf.sub(tf.matmul(tf.transpose(x), h), tf.matmul(tf.transpose(x_sample), h_sample)))
- bv_adder = tf.mul(lr/size_bt, tf.reduce_sum(tf.sub(x, x_sample), 0, True))
- bh_adder = tf.mul(lr/size_bt, tf.reduce_sum(tf.sub(h, h_sample), 0, True))
- #When we do sess.run(updt), TensorFlow will run all 3 update steps
- updt = [W.assign_add(W_adder), bv.assign_add(bv_adder), bh.assign_add(bh_adder)]
5.运行 Graph 算法图:
1.先初始化变量
- with tf.Session() as sess:
- #First, we train the model
- #initialize the variables of the model
- init = tf.initialize_all_variables()
- sess.run(init)
起首须要 reshape 每首歌,以便于响应的向量表示可以更好地被用于练习模型。
- for epoch in tqdm(range(num_epochs)):
- for song in sonGS:
- #The songs are stored in a time x notes format. The size of each song is timesteps_in_song x 2*note_range
- #Here we reshape the songs so that each training example is a vector with num_timesteps x 2*note_range elements
- song = np.array(song)
- song = song[:np.floor(song.shape[0]/num_timesteps)*num_timesteps]
- song = np.reshape(song, [song.shape[0]/num_timesteps, song.shape[1]*num_timesteps])
2.接下来就来练习 RBM 模型,一次练习一个样本
- for i in range(1, len(song), batch_size):
- tr_x = song[i:i+batch_size]
- sess.run(updt, feed_dict={x: tr_x})
模型完全练习好后,就可以用来生成 music 了。
3.须要练习 Gibbs chain
个中的 visible nodes 先初始化为0,来生成一些样本。
然后把向量 reshape 成更好的格局来 playback。
- sample = gibbs_sample(1).eval(session=sess, feed_dict={x: np.zeros((10, n_visible))})
- for
推荐阅读
日前,四川省当局印发《四川省城乡垃圾处理举措措施扶植三年推动筹划》(以下简称《筹划》)。《筹划》提出,到2019岁尾,我省生活垃圾无害化处理才能将达7.05万吨/日,生活垃圾处理举措措施>>>详细阅读
本文标题:如何用 TensorFlow 教机器人作曲?秘诀原来是这样
地址:http://www.17bianji.com/lsqh/35102.html
1/2 1