作家
登录

如何用 TensorFlow 教机器人作曲?秘诀原来是这样

作者: 来源: 2017-05-09 17:04:45 阅读 我要评论

接着须要定义 timestep ,可见层和隐蔽层的大年夜小。

4.更新变量:

  1. size_bt = tf. CA 
  2.  
  3. st(tf.shape(x)[0], tf.float32) 
  4.  
  5. W_adder = tf.mul(lr/size_bt, tf.sub(tf.matmul(tf.transpose(x), h), tf.matmul(tf.transpose(x_sample), h_sample))) 
  6.  
  7. bv_adder = tf.mul(lr/size_bt, tf.reduce_sum(tf.sub(x, x_sample), 0, True)) 
  8.  
  9. bh_adder = tf.mul(lr/size_bt, tf.reduce_sum(tf.sub(h, h_sample), 0, True)) 
  10.  
  11. #When we do sess.run(updt), TensorFlow will run all 3 update steps 
  12.  
  13. updt = [W.assign_add(W_adder), bv.assign_add(bv_adder), bh.assign_add(bh_adder)] 

5.运行 Graph 算法图:

1.先初始化变量

  1. with tf.Session() as sess: 
  2.  
  3. #First, we train the model 
  4.  
  5. #initialize the variables of the model 
  6.  
  7. init = tf.initialize_all_variables() 
  8.  
  9. sess.run(init) 

起首须要 reshape 每首歌,以便于响应的向量表示可以更好地被用于练习模型。

  1. for epoch in tqdm(range(num_epochs)): 
  2.  
  3. for song in sonGS: 
  4.  
  5. #The songs are stored in a time x notes format. The size of each song is timesteps_in_song x 2*note_range 
  6.  
  7. #Here we reshape the songs so that each training example is a vector with num_timesteps x 2*note_range elements 
  8.  
  9. song = np.array(song) 
  10.  
  11. song = song[:np.floor(song.shape[0]/num_timesteps)*num_timesteps] 
  12.  
  13. song = np.reshape(song, [song.shape[0]/num_timesteps, song.shape[1]*num_timesteps]) 

2.接下来就来练习 RBM 模型,一次练习一个样本

  1. for i in range(1, len(song), batch_size): 
  2.  
  3. tr_x = song[i:i+batch_size] 
  4.  
  5. sess.run(updt, feed_dict={x: tr_x}) 

模型完全练习好后,就可以用来生成 music 了。

3.须要练习 Gibbs chain

个中的 visible nodes 先初始化为0,来生成一些样本。

然后把向量 reshape 成更好的格局来 playback。

  1. sample = gibbs_sample(1).eval(session=sess, feed_dict={x: np.zeros((10, n_visible))}) 
  2.  
  3. for

      推荐阅读

      垃圾收集转运处理将信息化监管

    日前,四川省当局印发《四川省城乡垃圾处理举措措施扶植三年推动筹划》(以下简称《筹划》)。《筹划》提出,到2019岁尾,我省生活垃圾无害化处理才能将达7.05万吨/日,生活垃圾处理举措措施>>>详细阅读


    本文标题:如何用 TensorFlow 教机器人作曲?秘诀原来是这样

    地址:http://www.17bianji.com/lsqh/35102.html

关键词: 探索发现

乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

网友点评
自媒体专栏

评论

热度

精彩导读
栏目ID=71的表不存在(操作类型=0)