[Volo.Abp升级笔记]使用旧版Api规则替换RESTful Api以兼容老程序

【.Net动态Web API】动态方法RESTful风格 【.Net动态Web API】动态方法RESTful风格就介绍到这边啦!这个系列预计一天一篇文章,想要学习的可以关注起来!文章会持续更新,大家有想要了解的功能点或者话题,可以在评论区告诉我! 阅读详情


Volo.Abp 配置应用层自动生成Controller,增删查改服务(CrudAppService)将会以RESTful Api的方式生成对应的接口
( 官方文档),这与旧版本的Abp区别很大。RESTful固然好,虽然项目里新的Api会逐步使用RESTful Api代替旧的,但在前后端分离的项目中已经定好的接口,往往需要兼容之前的方式。

原理分析

旧版行为

应用层继承于AsyncCrudAppService的类,在Web层调用CreateControllersForAppServices后,Abp框架将以默认的规则实现Controller,具体的规则如下:

  • Get: 如果方法名称以GetList,GetAll或Get开头.
  • Put: 如果方法名称以Put或Update开头.
  • Delete: 如果方法名称以Delete或Remove开头.
  • Post: 如果方法名称以Create,Add,Insert或Post开头.
  • Patch: 如果方法名称以Patch开头.
  • 其他情况, Post 为 默认方式.
  • 自动删除’Async’后缀.

例子:
在这里插入图片描述

新版行为:
将会以RESTful Api的方式生成对应的接口,具体规则如下

服务方法名称HTTP MethodRoute
GetAsync(Guid id)GET/api/app/book/{id}
GetListAsync()GET/api/app/book
CreateAsync(CreateBookDto input)POST/api/app/book
UpdateAsync(Guid id, UpdateBookDto input)PUT/api/app/book/{id}
DeleteAsync(Guid id)DELETE/api/app/book/{id}
GetEditorsAsync(Guid id)GET/api/app/book/{id}/editors
CreateEditorAsync(Guid id, BookEditorCreateDto input)POST/api/app/book/{id}/editor

例子
在这里插入图片描述

开始改造

更换基类型

为了兼容旧版Abp,先来还原增删查改服务(CrudAppService)的方法签名。
注意到

  1. Volo.Abp 中 UpdateAsync方法签名已与旧版不同
  2. 旧版中的GetAllAsync方法,被GetListAsync所取代。

新建一个CrudAppServiceBase类继承 CrudAppService。并重写UpdateAsync和GetListAsync方法。

为了还原旧版的接口,将用private new关键字覆盖掉 UpdateAsync,GetListAsync方法,并重新实现更改和查询列表的功能




public abstract class CrudAppServiceBase<TEntity, TGetOutputDto, TGetListOutputDto, TKey, TGetListInput, TCreateInput, TUpdateInput>
    : CrudAppService<TEntity, TGetOutputDto, TGetListOutputDto, TKey, TGetListInput, TCreateInput, TUpdateInput>
    where TEntity : class, IEntity<TKey>
        where TGetOutputDto : IEntityDto<TKey>
where TGetListOutputDto : IEntityDto<TKey>
{
    protected CrudAppServiceBase(IRepository<TEntity, TKey> repository)
: base(repository)
    {

    }

    private new Task<TGetOutputDto> UpdateAsync(TKey id, TUpdateInput input)
    {
        return base.UpdateAsync(id, input);
    }
    private new Task<PagedResultDto<TGetListOutputDto>> GetListAsync(TGetListInput input)
    {
        return base.GetListAsync(input);
    }

    public virtual async Task<TGetOutputDto> UpdateAsync(TUpdateInput input)
    {
        await CheckUpdatePolicyAsync();
        var entity = await GetEntityByIdAsync((input as IEntityDto<TKey>).Id);
        MapToEntity(input, entity);
        await Repository.UpdateAsync(entity, autoSave: true);
        return await MapToGetOutputDtoAsync(entity);

    }
    public virtual Task<PagedResultDto<TGetListOutputDto>> GetAllAsync(TGetListInput input)
    {
        return this.GetListAsync(input);
    }   

}


基于扩展性考虑,我们可以像官方实现一样做好类型复用

public abstract class CrudAppServiceBase<TEntity, TEntityDto, TKey>
    : CrudAppServiceBase<TEntity, TEntityDto, TKey, PagedAndSortedResultRequestDto>
    where TEntity : class, IEntity<TKey>
    where TEntityDto : IEntityDto<TKey>
{
    protected CrudAppServiceBase(IRepository<TEntity, TKey> repository)
        : base(repository)
    {

    }
}

public abstract class CrudAppServiceBase<TEntity, TEntityDto, TKey, TGetListInput>
    : CrudAppServiceBase<TEntity, TEntityDto, TKey, TGetListInput, TEntityDto>
    where TEntity : class, IEntity<TKey>
    where TEntityDto : IEntityDto<TKey>
{
    protected CrudAppServiceBase(IRepository<TEntity, TKey> repository)
        : base(repository)
    {

    }
}


public abstract class CrudAppServiceBase<TEntity, TEntityDto, TKey, TGetListInput, TCreateInput>
    : CrudAppServiceBase<TEntity, TEntityDto, TKey, TGetListInput, TCreateInput, TCreateInput>
    where TEntity : class, IEntity<TKey>
    where TEntityDto : IEntityDto<TKey>
{
    protected CrudAppServiceBase(IRepository<TEntity, TKey> repository)
        : base(repository)
    {

    }
}

public abstract class CrudAppServiceBase<TEntity, TEntityDto, TKey, TGetListInput, TCreateInput, TUpdateInput>
: CrudAppServiceBase<TEntity, TEntityDto, TEntityDto, TKey, TGetListInput, TCreateInput, TUpdateInput>
where TEntity : class, IEntity<TKey>
where TEntityDto : IEntityDto<TKey>
{
    protected CrudAppServiceBase(IRepository<TEntity, TKey> repository)
        : base(repository)
    {

    }

    protected override Task<TEntityDto> MapToGetListOutputDtoAsync(TEntity entity)
    {
        return MapToGetOutputDtoAsync(entity);
    }

    protected override TEntityDto MapToGetListOutputDto(TEntity entity)
    {
        return MapToGetOutputDto(entity);
    }
}

重写接口

重写增删查改服务接口

public interface IBaseCrudAppService<TGetOutputDto, TGetListOutputDto, in TKey, in TGetListInput, in TCreateInput, in TUpdateInput>

    {
        Task<TGetOutputDto> GetAsync(TKey id);

        Task<PagedResultDto<TGetListOutputDto>> GetAllAsync(TGetListInput input);

        Task<TGetOutputDto> CreateAsync(TCreateInput input);

        Task<TGetOutputDto> UpdateAsync(TUpdateInput input);

        Task DeleteAsync(TKey id);

    }

基于扩展性考虑,我们可以像官方实现一样做好类型复用

public interface IBaseCrudAppService<TEntityDto, in TKey>
    : IBaseCrudAppService<TEntityDto, TKey, PagedAndSortedResultRequestDto>
{

}

public interface IBaseCrudAppService<TEntityDto, in TKey, in TGetListInput>
    : IBaseCrudAppService<TEntityDto, TKey, TGetListInput, TEntityDto>
{

}

public interface IBaseCrudAppService<TEntityDto, in TKey, in TGetListInput, in TCreateInput>
    : IBaseCrudAppService<TEntityDto, TKey, TGetListInput, TCreateInput, TCreateInput>
{

}

public interface IBaseCrudAppService<TEntityDto, in TKey, in TGetListInput, in TCreateInput, in TUpdateInput>
    : IBaseCrudAppService<TEntityDto, TEntityDto, TKey, TGetListInput, TCreateInput, TUpdateInput>
{

}

将应用服务接口IReservationAppService继承于IBaseCrudAppService和IApplicationService

public interface IReservationAppService: IBaseCrudAppService<ReservationDto, long>, IApplicationService
{
    //除增删查改业务的其他业务
}

创建应用服务类ReservationAppService,此时应用服务派生自CrudAppServiceBase,应用服务应该会完全实现接口

public class ReservationAppService : CrudAppServiceBase<Workflow.Reservation.Reservation, ReservationDto, long>, IReservationAppService
{
    ...
}

替换默认规则

Abp封装了Controller自动生成规则,利用了Asp.Net MVC的约定接口IApplicationModelConvention,这一特性,所谓规则即Convention,AbpServiceConvention是此接口的实现类,在此类中约定了如何将应用层程序集增删查改服务(CrudAppService)中的成员方法,按上述规则生成Controller。

规则的具体代码封装在ConventionalRouteBuilder里

既然是默认规则方式,我们就重写一个自定义的Convention来代替它默认的那个。
假设有领域Workflow,在Web层中新建WorkflowServiceConvention,把原AbpServiceConvention类中的所有内容复制到这个类中

public class WorkflowServiceConvention : IAbpServiceConvention, ITransientDependency
{

}

将不需要用到的对象删掉

// 删除 protected IConventionalRouteBuilder ConventionalRouteBuilder { get; } 

重写CreateAbpServiceAttributeRouteModel

protected virtual AttributeRouteModel CreateAbpServiceAttributeRouteModel(string rootPath, string controllerName, ActionModel action, string httpMethod, [CanBeNull] ConventionalControllerSetting configuration)
{
    return new AttributeRouteModel(
        new RouteAttribute(
                $"api/services/{rootPath}/{controllerName}/{action.ActionName}"
        )
    );
}

在Web层的Module文件WorkflowHostModule中,添加WorkflowApplicationModule

Configure<AbpAspNetCoreMvcOptions>(options =>
{
    options
        .ConventionalControllers
        .Create(typeof(WorkflowApplicationModule).Assembly);
});

用WorkflowServiceConvention替换原始的AbpServiceConvention实现。

Configure<MvcOptions>(options =>
{
    options.Conventions.RemoveAt(0);
    options.Conventions.Add(convention.Value);
});

在微服务架构中的问题

Asp.Net MVC在微服务的网关层中无法通过仅引用应用层方法的接口,生成Controller,即便改写 ControllerFeatureProvider, 还是需要引用实现类,这些实现类在应用层中。
但网关仅仅依赖定义层,若要拿到实现类,将改变微服务架构的依赖关系。

在官方的微服务实例中,也没有用Controller的自动生成,在这个issue中作者也给出了解答
https://github.com/abpframework/abp/issues/1731
在这里插入图片描述

因此如果想达到目的,只能用重写controller基类的方式了,这个方式好处在于简单好用,可读性和可维护性高,缺陷就是每写一个应用层类,需要写一个对应的Controller类,但在项目不多用CV大法还是可以接受的。

新建WorkflowController并继承于AbpControllerBase,并创建增删查改(Curd)的终结点路由,通过调用ITAppService的方法,实现各业务功能

public abstract class WorkflowController<ITAppService, TGetOutputDto, TGetListOutputDto, TKey, TGetListInput, TCreateInput, TUpdateInput>
    : AbpControllerBase
where ITAppService : IBaseCrudAppService<TGetOutputDto, TGetListOutputDto, TKey, TGetListInput, TCreateInput, TUpdateInput>
        where TGetOutputDto : IEntityDto<TKey>
where TGetListOutputDto : IEntityDto<TKey>
{


    protected WorkflowController()
    {
        LocalizationResource = typeof(WorkflowResource);
    }


    private readonly ITAppService _recipeAppService;

    public WorkflowController(ITAppService recipeAppService)
    {
        _recipeAppService = recipeAppService;
    }

    [HttpPost]
    [Route("Create")]

    public async Task<TGetOutputDto> CreateAsync(TCreateInput input)
    {
        return await _recipeAppService.CreateAsync(input);
    }

    [HttpDelete]
    [Route("Delete")]
    public async Task DeleteAsync(TKey id)
    {
        await _recipeAppService.DeleteAsync(id);
    }

    [HttpGet]
    [Route("GetAll")]
    public async Task<PagedResultDto<TGetListOutputDto>> GetAllAsync(TGetListInput input)
    {
        return await _recipeAppService.GetAllAsync(input);
    }

    [HttpGet]
    [Route("Get")]
    public async Task<TGetOutputDto> GetAsync(TKey id)
    {
        return await _recipeAppService.GetAsync(id);
    }

    [HttpPut]
    [Route("Update")]
    public async Task<TGetOutputDto> UpdateAsync(TUpdateInput input)
    {
        return await _recipeAppService.UpdateAsync(input);
    }
}

基于扩展性考虑,我们可以做好类型复用

public abstract class WorkflowController<ITAppService, TEntityDto, TKey>
      : WorkflowController<ITAppService, TEntityDto, TKey, PagedAndSortedResultRequestDto>
      where ITAppService : IBaseCrudAppService<TEntityDto, TKey>
      where TEntityDto : IEntityDto<TKey>
{
    protected WorkflowController(ITAppService appService)
        : base(appService)
    {

    }
}

public abstract class WorkflowController<ITAppService, TEntityDto, TKey, TGetListInput>
    : WorkflowController<ITAppService, TEntityDto, TKey, TGetListInput, TEntityDto>
    where ITAppService : IBaseCrudAppService<TEntityDto, TKey, TGetListInput>
    where TEntityDto : IEntityDto<TKey>
{
    protected WorkflowController(ITAppService appService)
        : base(appService)
    {

    }
}


public abstract class WorkflowController<ITAppService, TEntityDto, TKey, TGetListInput, TCreateInput>
 : WorkflowController<ITAppService, TEntityDto, TKey, TGetListInput, TCreateInput, TCreateInput>
 where ITAppService : IBaseCrudAppService<TEntityDto, TKey, TGetListInput, TCreateInput>
 where TEntityDto : IEntityDto<TKey>
{
    protected WorkflowController(ITAppService appService)
        : base(appService)
    {

    }
}

public abstract class WorkflowController<ITAppService, TEntityDto, TKey, TGetListInput, TCreateInput, TUpdateInput>
: WorkflowController<ITAppService, TEntityDto, TEntityDto, TKey, TGetListInput, TCreateInput, TUpdateInput>
where ITAppService : IBaseCrudAppService<TEntityDto, TKey, TGetListInput, TCreateInput, TUpdateInput>
where TEntityDto : IEntityDto<TKey>
{
    protected WorkflowController(ITAppService appService)
        : base(appService)
    {

    }

}


创建实际的Controller,定义Area名称和Controller路由“api/Workflow/reservation”

此时Controller派生自WorkflowController,应用服务应该会完全实现接口

[Area(WorkflowRemoteServiceConsts.ModuleName)]
[RemoteService(Name = WorkflowRemoteServiceConsts.RemoteServiceName)]
[Route("api/Workflow/reservation")]
public class ReservationController : WorkflowController<IReservationAppService, ReservationDto,long>, IReservationAppService
{
    private readonly IReservationAppService _reservationAppService;

    public ReservationController(IReservationAppService reservationAppService):base(reservationAppService)
    {
        _reservationAppService = reservationAppService;
    }
}

运行程序,我们将得到一个旧版的接口
在这里插入图片描述

每次为新的应用服务类创建Controller,只需要新建一个派生自WorkflowController类的Controller,并指定一个应用服务类对象。就完成了,不需要自己写一大堆的控制器方法。

volo.abp.freesql:FreeSql是一个优秀的Orm框架,首先感谢FreeSql的作者,♡Volo.Abp.FreeSql作为扩展模块,集成到Abp.VNext中。方便应用 volo.abp.freesql FreeSql是一个优秀的Orm框架,首先感谢FreeSql的作者,Abp VNext是一个很优秀的后台框架。 使用者做好任何事情也与本作者无关。觉得好用请给个星 FreeSql与Abp Venxt的设计模式交替,导致FreeSql某些功能不能在Abp Venxt应用 须知: 每个SqlConnection GetFreeSql()返回的IFreeSql实例相同;即同一个TDbContext类型的多个DbContext实例返回的IFreeSql实例相同 可以对fsql设置Aop事件,选择监视SQL; IFreeSql的ICodeFirst不可用 IFreeSql本身的成员IDbFirst,Transaction不可用; 安装 dotnet添加软件包AbpVNext.FreeSql 使用 ///在一个模块引入Volo.Abp.FreeSql 立即下载

相关推荐

深入解析:el-table合并单元格

  在企业级应用开发中,我们经常需要处理复杂的数据展示需求。在构建复杂的数据展示后台时,我们常常需要将表格中具有相同属性的行进行视觉上的合并,以提升信息的聚合度和可读性。在 Element Plus 的 el-table 组件中,span-method 属性是实现单元格合并的核心机制,允许开发者自定义单元格的合并逻辑,开发者可以通过实现自定义合并策略来满足各种负责需求。  合并行的本质是通过计算相邻行数据的相似性,确定满足合并的单元格范围,然后通过 DOM 操作将多个单元格合并为一个。这种操作在前端数据可视

独泪了无痕 229

怎样优雅地增删查改(一):从0开始搭建Volo.Abp项目

软件系统中数据库或者持久层的基本操作功能可以用Curd描述,Curd即 增加(Create)、更新(Update)、读取查询(Retrieve)和删除(Delete), 这4个单词的首字母。 在常见的业务系统中,对数据的大部分操作都是Curd,在实践的过程中对数据的筛选、排序、分页、关联查询等功能抽象和封装。 本系列博文将从0开始,逐步搭建一个基于Volo.Abp + Vue 的前后端分离的,具有Curd通用查询功能的项目。 项目介绍 本项目是基于一个简单的用户健康数据管理系统,我们将对业务常用的查询功能进

jevonsflash的专栏 1671

PAM4信号测试实战:从眼图分析到误码率测量的技术演进

在高速数字系统设计中,信号完整性测试是确保数据传输可靠性的核心环节。其基本原理在于通过时域和频域分析,精确评估信号在传输过程中的质量衰减与失真。随着数据速率向56Gbps及以上演进,传统的NRZ编码面临带宽瓶颈,而PAM4调制技术通过在每个符号周期内承载更多比特信息,成为提升信道效率的关键路径。这项技术的工程价值在于,它允许在相同带宽下实现翻倍的数据吞吐量,这对于数据中心互联、PCIe 6.0及800G以太网等高速接口至关重要。然而,PAM4信号电平间距更小,对噪声和抖动极为敏感,导致其原始误码率显著升高,

weixin_42522817的博客 657

【Abp VNext】实战入门(二):应用层服务创建、简单服务、继承CrudAppService增删改查服务

应用层: AoRuiDe.GasMonitoring.Application 一、创建简单应用层服务: 1、应用层 根目录新增AbpUserAppService.cs [AllowAnonymous] //默认不做权限控制 public class AbpUserAppService: ApplicationService { public string Test(string value) { return val..

刘永洪的博客 3112

大众点评商家及评分数据(2012-2025)

大众点评及商家评分数据库全面覆盖全国范围内多个城市的商户信息,涵盖餐饮、购物、休闲娱乐等多个消费领域,包含商家基础信息、地理坐标、分类体系、经营状态、用户评价、消费水平及服务设施等共计28个字段。

Sunny9qx的博客 2693

高分辨率航拍图像的目标检测切图优化策略

本文深入探讨了高分辨率航拍图像目标检测中的切图优化策略。针对大尺寸图像直接缩放导致小目标信息丢失的问题,文章详细阐述了基于重叠切割的核心方法,包括如何根据目标尺寸确定切图尺寸与重叠率,并提供了从切图到坐标还原的完整代码实现与避坑指南,有效提升检测精度与效率。

xk7n92h3p5m的博客 1113

.NET Core之 ABP从入门到精通

ABP是一套基于WEB的快速开发引用框架,和DDD领域驱动开发有很好的结合。 主要特性:模块化,多租户,认证授权,虚拟文件系统,主题系统,后台作业,事件总线,对象映射,依赖注入,数据过滤等。 接下来用代码的方式介绍ABP框架的使用。 一.VS创建一个ABP控制台程序打出Hello word! 1.首先引入框架包 Nuget中安装volo.abp.core 2.创建模块 所谓的ABP模块在代码中体现就是类,我们创建一个HelloABPModule的类,然后引入using Volo.Abp.Modulari

csdn2990的博客 1万+

西门子与汇川伺服脉冲连接(速度模式)

如何使用西门子PLC与汇川伺服进行脉冲连接

2301_77347966的博客 1万+

Volo.Abp升级小记(二)创建全新微服务模块

假设有一个按照搭建的微服务项目,并安装好了abp-cli。需要创建一个名为GDMK.CAH.Common的模块,并在模块中创建标签管理功能。

jevonsflash的专栏 2459

利用PaddleOCR识别增值税发票平台验证码(开箱即用)

下面直接讲解利用paddleocr识别的思路,为什么使用paddleocr,因为paddle中集成了较好的ocr文字识别模型,开箱即用即可,废话不多说,剑指主题,识别思路步骤如下。

码王吴彦祖的博客 5544

checking OpenSSL library version... configure: error: OpenSSL >= 1.1.1 required (have “100020bf 解决方案

 本文主要介绍了checking OpenSSL library version… configure: error: OpenSSL >= 1.1.1 required (have “100020bf (OpenSSL 1.0.2k-fips 26 Jan 2017)”)解决方案,希望能对使用Linux的同学们有所帮助。 文章目录 1. 问题描述 2. 解决方案

weixin_43178406的博客 2万+

Vue + Volo.Abp 实现OAuth2.0客户端授权模式认证

只需要清除vuex或Cookies中的token即可,可以调用vue-oidc-client的signOut,但只是跳转到配置的登出地址,不会清除token(前提是redirectAfterSignout为true,并设置了post_logout_redirect_uri)创建continue/index.vue,简单的显示登录成功的提示,常用的提示有“登录成功,正在为您继续”,“登录成功,正在为您跳转”等友好提示。(D)客户端收到授权码,附上早先的"重定向URI",向认证服务器申请令牌。

jevonsflash的专栏 2521

实战:RK3568 Android14 集成 AP6212A WiFi/BT 二合一模块

AP6212A 的集成在 RK3568 上非常成熟。只要电源、32K 时钟、SDIO 线序、UART 流控这四点硬件没问题,软件上主要是 DTS 对应的 GPIO 别填错即可。希望这篇博文能帮你一次点亮 WiFi 和蓝牙!

qq_33427070的博客 1449

ABP 框架ICrudAppService详解

示例:`BDMaterialDto` 可能包含物料的属性,比如 `Id`(ID)、`Name`(名称)、`Code`(编码)、`Price`(价格)等,但通常不包含数据库实体的所有字段(为了安全性和性能)。示例:在 `GetAsync(long id)` 或 `DeleteAsync(long id)` 中,`id` 参数就是 `long` 类型。在 ABP 中,`ICrudAppService` 的方法通常是异步的(返回 `Task` 或 `Task<T>`),以支持高性能的异步编程。

专注于前沿技术的探索与实践,热衷于从代码逻辑、架构设计到行业应用等多维度深挖技术本质。期待在技术之路上与你共同成长~ 1060

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Abp源码分析之虚拟文件系统Volo.Abp.VirtualFileSystem

Volo.Abp.VirtualFileSystem 是 ABP 框架中的一个重要组件,提供了一种抽象文件系统的方式,使应用程序可以轻松访问和管理文件资源。本文介绍了如何在 MVC 项目中使用 `Volo.Abp.VirtualFileSystem`,包括新建项目、配置模块、添加资源文件以及读取资源文件的具体步骤。通过统一的接口处理文件和目录,无论实际存储位置如何,应用程序都能更加灵活地切换不同的文件存储方式。

shiningrise的博客 582

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

C# Volo.Abp使用原生sql语句查询

这里写自定义目录标题欢迎使用Markdown编辑器新的改变功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式前言一、pandas是什么?二、使用步骤1.引入库2.读入数据总结插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你的文章UML 图表FLowchart流程图导出与导入导出导入 欢迎使用Markdown编辑器 你好! 这是你第一次使用

KKKoyomi的博客 3832

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

ABP vnext 应用服务知识整理

使用 用法 ICrudAppService创建应用服务 例3 IAsyncCrudAppService 例1 IApplicationService创建应用服务 例2 获取服务 例4 例1 为Task实体创建一个CRUD应用服务 Task.cs public class Task : Entity, IHasCreationTime { public string Title { get; set; } public string Description

威风的风的博客 840

在Volo.Abp微服务中使用SignalR

假设需要通过Signalr发送消息通知,并在前端接收消息通知的功能。

jevonsflash的专栏 1924

入门系列- ABP 本地化

1.System.IO.IOException:“Failed to bind to address http://localhost:8102.” 2.SocketException: 以一种访问权限不允许的方式做了一个访问套接字的尝试。 3.AggregateException: One or more errors occurred. (以一种访问权限不允许的方式做了一个访问套接字的尝试...

研究、探索、分享与成长 8796

使用Volo.Abp读取Sqlite表中数据

Volo.Abp Sqlite EntityFramework

bjxingch的博客 1039

[2018-12-18]ABP中的AsyncCrudAppService介绍

前言 自从写完上次略长的《用ABP入门DDD》后,针对ABP框架的项目模板初始化,我写了个命令行工具Abp-CLI,其中子命令abplus init可以从github拉取项目模板以初始化项目。自然而然的,又去处理了aspnetboilerplate/module-zero-core-template这个项目模板库当中的vue项目模板,解决以前发现的,又貌似一直没人修复的几个问题PR362,PR3...

weixin_30786657的博客 733

C# Abp框架入门系列文章(一)

随着技术的进步,各式各样的框架层出不穷,轮子越来越多,那么有没有哪些优秀的开发框架供我们使用呢?如果我们能够将各方面优秀的框架集合起来,应用到项目开发中,我们的工作是不是能事半功倍呢?而且各个框架的使用方向不同,很多配置也不同,如果能够将繁杂的基础工作集成起来,由统一的框架来完成,那么我们就可以专注于业务逻辑,提高工作效率。现在Abp就是这么一个框架,使用流行技术开发现代web应用程序的最佳实践。本文作为Abp框架的入门文章,仅供学习分享使用,如有不足之处,还请指正。

绳锯木断,水滴石穿,专心写文,无问西东!!! 1万+

abp的application service形成的restful api 和nswagger的集成时, 返回值为null

原因是ABP把application service的返回值包装到了 AjaxResponse中, 最终的json字符串放到result里。 类似{"result":{"accessToken":"5","encryptedAccessToken":"6","expireInSeconds":86400,"userId":2},"targetUrl&quo

muzizongheng的专栏 2165

ICrudAppService 精简形式

如果代码简化为以下形式:```csharp```这仍然是基于 ABP 框架 的一个应用服务接口,但相比之前的完整版本,它使用了 `ICrudAppService` 的简化形式。下面我将详细解释这段代码的含义、作用、与完整版的区别,以及在 ABP 框架中的意义,用中文清晰说明。1. 代码解析1.1 接口名称:`IMaterialAppService`

专注于前沿技术的探索与实践,热衷于从代码逻辑、架构设计到行业应用等多维度深挖技术本质。期待在技术之路上与你共同成长~ 767
上一篇: 探究C# dynamic动态类型本质
下一篇: [MAUI 项目实战] 手势控制音乐播放器(二): 手势交互
林晓lx
林晓lx 2017年优快云移动跨平台大赛优秀奖获得者 2017年优快云移动跨平台大赛优秀奖获得者
博客等级 码龄15年 3761粉丝 123原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

林晓lx

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值