2 Star 1 Fork 3

风酒 / Vulcan

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
contribute
Sync branch
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README
LGPL-3.0

目录

  • 一、项目简介
    • 1.项目简介
    • 2.项目目标
  • 二、项目结构
    • 1.库
    • 2.文件结构
    • 2.项目结构图
  • 三、全局配置
    • 1.数据集本地文件夹
  • 四、简明样例
    • 1.定义net结构
    • 2.定义配置文件
      • 2.1train配置
      • 2.2predict配置
    • 1.训练
    • 2.预测
  • 五、打印和tensorboard
    • 1.配置
    • 2.网络结构
    • 3.训练过程
    • 4.tensorboard

一、项目简介

1.项目简介

Vulcan(匠神)项目是基于tensorflow的深度学习复用框架,旨在封装深度模型搭建过程中的复用部分(pre-processing、evaluate和validate等),提高搭建模型的效率,更聚焦与模型本身。

Vulcan使用配置(.yml)控制训练、预测流程,封装训练、预测参数,复用只需更改配置,简单快捷。

2.项目目标

  • 1.提取深度学习工程的核心流程,复用化封装(已完成简单核心)。
  • 2.一行代码训练,一行代码预测。
  • 3.封装DNN、CNN和RNN的常规模型。
  • 4.可视化搭建网络。
  • 5.一键导出。

二、项目结构

1.库

需要安装到的库

tqdm
pyyaml
numpy
pandas
tensorflow

2.文件目录

  • base
    • main 入口方法
  • config
    • core 核心配置,存放控制训练预测的.yml文件
      • default 默认配置
      • train 训练配置
      • predict 预测配置
    • glob
      • config 一些全局配置
      • global_pool 全局变量池,供整个运行时的全局加载
    • load_config.py 入口
  • data 训练数据
    • board tensorboard文件
    • log 日志文件
    • model 训练出的模型文件
    • model_img 模型结构图
  • dataset
    • parser 解析器封装(主要使用tf.data.Dataset)
    • preprocessor 预处理器
    • reader 读取器,读取原始数据集
    • build_dataset.py 入口
  • dto 数据传输对象
  • eval 校验方法
  • element 复用方法(CNN、RNN复用方法,如conv2d、pool等的进一步封装)
  • embed 词嵌入模块
  • eval 验证方法
  • model 模型核心网络
    • base 模型核心(无需关注)
    • loss 损失函数模块
    • net 网络结构
    • optimizer 优化器
    • predict 自定义预测方法
    • load_model.py 入口
  • test 测试方法
  • utils 工具包
  • train.py 一行代码训练样例
  • predict.py 一行代码预测样例

3.项目结构图

输入图片说明

三、多设备配置

多个设备上运行本项目,多个设备上的数据集路径可能不同时,请配置 config/glob/config.py 中的DATASET_ROOT,运行项目时在train配置文件中的reader.dataset使用最后一个文件夹名即可。

如果不需多设备频繁切换,则可以忽略配置本项,在train配置文件中的reader.dataset使用绝对路径即可。

# 本地数据集路径
DATASET_ROOT = get_dataset_path([
    'D:\\dl_data\\sample',
    'F:\\data_deeplearning\\sample_data'
])

四、简明样例

构建一个单层dnn作为样例

1.定义net结构

一般放在定义的net结构放在 model/net 路径下,定义的结构如下:

def net(self):
    with tf.name_scope('fc_1'):
        layer1 = fc_layer(self.xs, 10, activation_func=tf.nn.softmax)  # 隐藏层
    with tf.name_scope('fc_2'):
        self.y_pred = fc_layer(layer1, 10, activation_func=tf.nn.softmax)  # 隐藏层

注意:形参必须写self,输入写self.xs即可,最终的输出一定要赋给self.y_pred,输入的shape和dtype暂不关注,后续会在配置文件中配置。

2.定义配置文件

配置文件的含义和限制还在项目中查看 config/core/train/templet.yml和readme文档。

2.1train配置

#--- dataset.reader模块配置----
reader:
  dataset: 'mnist'
  module: 'dataset.reader.mnist_reader'
#--- model.net配置-----
net:
  module: 'model.net.dnn.single_layer.single_layer'
#--- model初始化配置-----
xs_shape: [784]
xs_dtype: 'float'
ys_shape: [10]
ys_dtype: 'float'
#--- model train配置-----
epoch: 2
batch_size: 60
# 保存配置
save:
  is_save: false
# 损失函数
optimizer:
  name: sgd

2.2predict配置

#--- common配置-----
module: 'model.net.dnn.single_layer.single_layer'
xs_shape: [784]  # xs shape
#--- predict配置-----
load_model_dir: "data/model/dnn/single_layer/10151326/model"
predict_mod: 'model.predict.default_predict'

3.训练

将train的配置文件传给train(),一键即可训练。

from base.main import train
if __name__ == '__main__':
    train('config/core/train/single_layer.yml')

4.预测

将predict的配置文件传给predict(),一键即可训练。

from base.main import predict
if __name__ == '__main__':
    # 一行预测
    y_pred = predict('config/core/predict/single_layer.yml', x)
    # 打印结果
    print('\033[35my:{}, y_pred:{}'.format(np.argmax(y, axis=1), np.argmax(y_pred, axis=1)))

五、打印和tensorboard

项目日志如下

1.配置

输入图片说明

2.网络结构

输入图片说明

输入图片说明

3.训练过程

输入图片说明

输入图片说明

4.tensorboard

会自动在浏览器弹出tensorboard,截图如下

输入图片说明

项目融合了embedding(词嵌入)、pre_process(预处理)、dataset(tf.data.Dataset)等模块

其中各个模块均抽取出可自定义的部分,可以通过配置直接选择已定义好的,或者自行写代码定义,在配置中配置即可。详细文档请移步本项目Wiki。

GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.

About

深度学习复用框架 expand collapse
Python
LGPL-3.0
Cancel

Releases

No release

Contributors

All

Activities

Load More
can not load any more
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/windandwine/Vulcan.git
git@gitee.com:windandwine/Vulcan.git
windandwine
Vulcan
Vulcan
dev

Search

344bd9b3 5694891 D2dac590 5694891