Google Magenta简介, 安装,使用简例_googlemagenta-程序员宅基地

技术标签: magenta  AI  Google Magenta  


Magenta是由google组织的一个项目组,专门进行基于机器学习的人工智能艺术方面的研究,包括自动作曲、音频生成、图画生成等方面。

资源:

Github地址: https://github.com/tensorflow/magenta

官网地址:   https://magenta.tensorflow.org/

讨论组: https://groups.google.com/a/tensorflow.org/forum/#!forum/magenta-discuss

网上Blog:

https://www.cnblogs.com/charlotte77/p/5664523.html

http://www.mamicode.com/info-detail-1443942.html

 

Conda 是一个开源的软件包管理系统和环境管理系统,用于安装多个版本的软件包及其依赖关系,并在它们之间轻松切换。Conda 是为 Python 程序创建的,适用于 Linux,OS X 和W indows,也可以打包和分发其他软件 [1] 

目前最流行的 Python 环境管理工具。

 

用conda创建虚拟环境:

conda create -n your_env_name python=X.X2.73.6)命令创建python版本为X.X、名字为your_env_name的虚拟环境

https://blog.csdn.net/lyy14011305/article/details/59500819


安装magenta包过程(安装现成的软件)参照github上的指导:

  1. 在unbuntu下安装anacoda---anaconda官网上有详细说明:http://docs.anaconda.com/anaconda/install/linux/
  2. 命令行: conda create -n magenta python=2.7 jupyter 创建虚拟环境
  3. source activate magenta ,或conda activate magenta激活刚刚创建的虚拟环境
  4. 按照github提示,先装一些依赖库:
    sudo apt-get install build-essential libasound2-dev libjack-dev,该指令好像最好在激活magenta后的命令行中输入。
    然后,pip install magenta,使用linux 的pip指令直接安装magenta,应该是将magenta安装到了刚刚创建的虚拟环境中。

测试magenta是否安装好:这些操作必须是在magenta这个环境下操作的

$ python

>>> import magenta

>>> magenta.__version__

注意:每打开一个新的terminal,需要先激活magenta虚拟环境,然后才能使用。


安装成功后,使用magenta

You can now train our various models and use them to generate music, audio, and images. You can find instructions for each of the models by exploring the models directory.

To get started, create your own melodies with TensorFlow using one of the various configurations of our Melody RNN model; a recurrent neural network for predicting melodies.

Github上提供了许多模型,例如声音,图像等:https://github.com/tensorflow/magenta/tree/master/magenta/models

以其中的一个模型drum rnn为例子,https://github.com/tensorflow/magenta/tree/master/magenta/models/drums_rnn ,github上的说明很详细,可以使用他们已经训练好的模型,也可以自己训练模型。

 

1. 直接使用已经训练好的Drum_rnn模型
首先下载drum_kit.mag文件(谷歌人已经训练出的现成的模型),然后写一个脚本:

#!/bin/bash

BUNDLE_PATH="/home/frank/FrankMaterials/Projects/MyGibHub/Magenta/Mymodels/drum_kit_rnn.mag" #<absolute path of .mag file>

CONFIG="one_drum"  #<one of 'one_drum' or 'drum_kit', matching the bundle>


drums_rnn_generate \

--config=${CONFIG} \

--bundle_file=${BUNDLE_PATH} \

--output_dir=/tmp/drums_rnn/generated \

--num_outputs=10 \

--num_steps=128 \

--primer_drums="[(36,)]"

exit 0

 

令脚本可以被执行的linux命令chmod +x 文件名

需要在前面建立的magenta虚拟环境下运行脚本,运行后会在output_dir目录下,生成很多个midi文件,可以直接播放。

 

2. 自己训练Drum_rnn模型


a)第一步:midi文件处理(最终保存成tfrecord格式

 Our first step will be to convert a collection of MIDI files into NoteSequences. NoteSequences are protocol buffers, which is a fast and efficient data format, and easier to work with than MIDI files. See Building your Dataset for instructions on generating a TFRecord file of NoteSequences. In this example, we assume the NoteSequences were output to /tmp/notesequences.tfrecord.

midi文件转换成NoteSequence的方法

https://github.com/tensorflow/magenta/blob/master/magenta/scripts/README.md

After installing Magenta, you can build your first MIDI dataset. We do this by creating a directory of MIDI files and converting them into NoteSequences. If you don't have any MIDIs handy, you can use the Lakh MIDI Dataset or find some at MidiWorld.

Warnings may be printed by the MIDI parser if it encounters a malformed MIDI file but these can be safely ignored. MIDI files that cannot be parsed will be skipped.

You can also convert MusicXML files and ABC files to NoteSequences.

If you are interested in adding your own model, please take a look at how we create our datasets under the hood: Data processing in Magenta

脚本:

INPUT_DIRECTORY=<folder containing MIDI and/or MusicXML files. can have child folders.>
# TFRecord file that will contain NoteSequence protocol buffers.
SEQUENCES_TFRECORD=/tmp/notesequences.tfrecord
convert_dir_to_note_sequences \
  --input_dir=$INPUT_DIRECTORY \
  --output_file=$SEQUENCES_TFRECORD \
  --recursive

补充资料

Protocol buffers are Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data – think XML, but smaller, faster, and simpler. You define how you want your data to be structured once, then you can use special generated source code to easily write and read your structured data to and from a variety of data streams and using a variety of languages.
Protocol Buffers,是Google公司开发的一种数据描述语言,类似于XML能够将结构化数据序列化,可用于数据存储、通信协议等方面。举例子:

person { name: "John Doe" ; email: "jdoe@"}

TFRecords其实是一种二进制文件,虽然它不如其他格式好理解,但是它能更好的利用内存,更方便复制和移动,并且不需要单独的标签文件。TFRecords文件格式在图像识别中有很好的使用,其可以将二进制数据和标签数据(训练的类别标签)数据存储在同一个文件中,它可以在模型进行训练之前通过预处理步骤将图像转换为TFRecords格式。TFRecords文件是一种二进制文件,其不对数据进行压缩,所以可以被快速加载到内存中.格式不支持随机访问,因此它适合于大量的数据流,但不适用于快速分片或其他非连续存取。

 

b)2步:Create SequenceExamples作为输入给模型的样本 还没成功

SequenceExamples are fed into the model during training and evaluation. Each SequenceExample will contain a sequence of inputs and a sequence of labels that represent a drum track. Run the command below to extract drum tracks from our NoteSequences(上一步中根据midi文件生成的) and save them as SequenceExamples.

Two collections of SequenceExamples will be generated, one for training, and one for evaluation, where the fraction of SequenceExamples in the evaluation set is determined by --eval_ratio. With an eval ratio of 0.10, 10% of the extracted drum tracks will be saved in the eval collection, and 90% will be saved in the training collection.

drums_rnn_create_dataset \

--config=<one of 'one_drum' or 'drum_kit'> \

--input=/tmp/notesequences.tfrecord \

--output_dir=/tmp/drums_rnn/sequence_examples \

--eval_ratio=0.10

 

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_35865125/article/details/87851324

智能推荐

[译]使用MVI打造响应式APP(四):独立性UI组件-程序员宅基地

文章浏览阅读130次。原文:REACTIVE APPS WITH MODEL-VIEW-INTENT - PART4 - INDEPENDENT UI COMPONENTS作者:Hannes Dorfmann译者:却把清梅嗅这篇博客中,我们将针对如何 如何构建独立组件 进行探讨,我将阐述为什么在我看来 父子关系会导致坏味道的代码,以及为何这种关系是没有意义的。有这样一个问题时不时涌现在我的脑海中—— MVI...

tensorflow经过卷积及池化层后特征图的大小计算_池化层后特征图尺寸-程序员宅基地

文章浏览阅读662次。https://blog.csdn.net/qq_32466233/article/details/81075288_池化层后特征图尺寸

使用vue-echarts异步数据加载,不能重新渲染页面问题。_vue echart初始化渲染过后无法重新渲染-程序员宅基地

文章浏览阅读3.3k次。一、问题说明我是用的是官方示例中的这个饼状图。结果在应用到项目中后发现利用axios请求到的数据无法渲染到页面中去。并且其中value值已经改变。二、解决办法用$set改变value的值,并且重新绘制一遍表格。$set是全局 Vue.set 的别名。$set用法:向响应式对象中添加一个属性,并确保这个新属性同样是响应式的,且触发视图更新。它必须用于向响应式对象上添加新属性,因为..._vue echart初始化渲染过后无法重新渲染

nrf51822 蓝牙协议栈 例程入门 点灯_nrf51822例程-程序员宅基地

文章浏览阅读6.6k次。1,参考文档: 青云蓝牙光盘V4.1\6.青云系列教程青风出品\3:BLE蓝牙应用篇\2.BLE实验第二节:蓝牙LED任务读写使用说明.pdf青云蓝牙光盘V4.1\6.青云系列教程青风出品\4:蓝牙原理详解手把手教你用蓝牙:蓝牙LED任务读写原理任务详解.pdf2,进入目录: 青云蓝牙光盘V4.1\5.青云测试代码\ 第三部分:BLE蓝牙实验\BLE实验3:按键蓝牙通知\B..._nrf51822例程

TortoiseGit小乌龟工具上传解析-程序员宅基地

文章浏览阅读5.2k次。使用tortoiseGit工具一直出错,由于没有设置自动获取putty key这一项,从网上找了一个教程,现分享如下,以做参考:前半部分参考网上的例子:http://www.showerlee.com/archives/1300,但会出现“git did not exit cleanly (exit code 128)”错误1.在D盘新建一个目录,例如"D:\Git",并进入目录右键目录空白处选择...

bindgetuserinfo="onGotUserInfo" and @getuserinfo="onGotUserInfo_component "pages/index/index" does not have a meth-程序员宅基地

文章浏览阅读1.9k次。发现使用uni-app获取UserInfo,结果使用微信官网栗子发现只弹出提示,没获取到值如下<button open-type="getUserInfo" lang="zh_CN" bindgetuserinfo="onGotUserInfo">获取用户信息</button>onGotUserInfo: function (e) { console.log(e) ..._component "pages/index/index" does not have a method "getuserinfo" to handle

随便推点

python translate函数_Python:内置函数makestrans()、translate()-程序员宅基地

文章浏览阅读287次。一、makestrans()格式: str.maketrans(intab,outtab);功能:用于创建字符映射的转换表,对于接受两个参数的最简单的调用方式,第一个参数是字符串,表示需要转换的字符,第二个参数也是字符串表示转换的目标。注:两个字符串的长度必须相同,为一一对应的关系。注:Python3.6中已经没有string.maketrans()了,取而代之的是内建函数:bytearray...._python maketrance

Set集合详解-程序员宅基地

文章浏览阅读5.7k次,点赞9次,收藏14次。set集合的简介,它的特点和遍历方式。介绍了HashSet重复元素存储底层原理,LinkedHashSet,TreeSet排序方法,SortedSet获取集合值的方法_set集合

详解智慧城市排水管理系统整体方案_污水处理智慧管理系统案列-程序员宅基地

文章浏览阅读3.6k次,点赞3次,收藏29次。随着城市规模的不断扩大和现代化程度的日益提高,城市排水管网越来越复杂,一些城市相继发生大雨内涝、管线泄漏爆炸、路面塌陷等事件,严重影响了人民群众生命财产安全和城市运行秩序。因此,摸清排水管网设施资产家底、建立排水管网地理信息系统,用现代化的技术手段对排水系统进行科学管理显得迫在眉睫。以时空信息为基础,充分利用感知监测网、物联网、云计算、移动互联网、工业控制和水力模型等新一代信息技术,全方位感..._污水处理智慧管理系统案列

详解NTFS文件系统_ntfs文件系统中,磁盘上的所有数据包括源文件都是以什么的形式存储-程序员宅基地

文章浏览阅读5.7k次,点赞4次,收藏13次。上篇在详解FAT32文件系统中介绍了FAT32文件系统存储数据的原理,这篇就来介绍下NTFS文件系统。NTFS、用过Windows系统的人都知道,它是一个很强大的文件系统,支持的功能很多,存储的原理也很复杂。目前绝大多数Windows用户都是使用NTFS文件系统,它主要以安全性和稳定性而闻名,下面是它的一些主要特点。安全性高:NTFS支持基于文件或目录的ACL,并且支持加密文件系统(E_ntfs文件系统中,磁盘上的所有数据包括源文件都是以什么的形式存储

【深度学习】【目标检测】损失函数smooth L1 Loss_smooth_l1_loss公式-程序员宅基地

文章浏览阅读1.2k次。pytorch之常用Loss函数总结参考文档L1、L2、smooth L1 Losssoftmax_cross_entropy_with_logitssparse_softmax_cross_entropy_with_logitsbinary_cross_entropysigmoid_cross_entropy参考文档参考文档参考文档L1、L2、smooth L1 Losssoftmax..._smooth_l1_loss公式

PAT 乙级 1017 (方法 + 代码)_pat 1017乙-程序员宅基地

文章浏览阅读462次。1017 A除以B (20 分)本题要求计算 A/B,其中 A 是不超过 1000 位的正整数,B 是 1 位正整数。你需要输出商数 Q 和余数 R,使得 A=B×Q+R 成立。输入格式:输入在一行中依次给出 A 和 B,中间以 1 空格分隔。输出格式:在一行中依次输出 Q 和 R,中间以 1 空格分隔。输入样例:123456789050987654321 7输出样例:17636..._pat 1017乙