Visual Studio Code中的任务配置文件tasks.json中的可选任务组tasks详解

VScode的两个json文件 (tasks.json、launch.json)针对C++构建任务 本文仅讲解tasks.json、launch.json文件常用的地方,以VScode自动生成的两个json文件为例。json是一种数据交换格式,不了解的自行百度。其实也没有太大必要了解很深,在本文中你只需知道它是用来存储配置信息的一堆键值对即可。因为此格式便于解析,大家都约定使用而已。换言之,只要你NB,设计的新格式合理,好用,没准大家都使用你的,那不大赚一笔?打住,想money想疯了-_-在说这两个json文件之前,有必要先说说g++的编译指令。为什么呢? 阅读详情
☞ ░ 前往老猿Python博客 ░ https://blog.csdn.net/LaoYuanPython

一、引言

vscode是支持通过配置可以实现类似Visual C++等IDE开发工具使用菜单和快捷键直接进行程序编译构建的,这样构建的任务可以结合后续的调试配置进行IDE环境的程序调试,不过在之前必须先通过vscode的编译构建任务配置文件tasks.json进行相关设置,当然配置的任务不仅限于编译,还可以做很多后台处理,如老猿就定义了一个任务用于显示vscode中可以使用的预定义变量的值,详细介绍请参考老猿在CSDN的博文《vscode中tasks.json文件使用的预定义变量及国产统信操作系统UOS下配置一个任务显示相关预定义变量的案例》。

二、tasks.json文件中的任务官方定义

在tasks.json配置文件中,可以定义多个任务,每个任务都包含了一些属性,例如任务名称、任务类型、执行命令、命令参数、工作目录、输出等,这些任务还可以指定执行依赖关系。通过配置tasks.json文件,可以方便地在Visual Studio Code中执行这些任务,提高开发效率。

tasks.json最重要的配置当然就是任务,关于任务配置项官方定义请见vscode的官方文档。

任务又分为基本任务和可选的任务组,下面是基本任务的官方相关定义及注释:

interface BaseTaskConfiguration {
  /**
   * The type of a custom task. Tasks of type "shell" are executed
   * inside a shell (e.g. bash, cmd, powershell, ...)
   */
  type: 'shell' | 'process';

  /**
   * The command to be executed. Can be an external program or a shell
   * command.
   */
  command: string;

  /**
   * Specifies whether a global command is a background task.
   */
  isBackground?: boolean;

  /**
   * The command options used when the command is executed. Can be omitted.
   */
  options?: CommandOptions;

  /**
   * The arguments passed to the command. Can be omitted.
   */
  args?: string[];

  /**
   * The presentation options.
   */
  presentation?: PresentationOptions;

  /**
   * The problem matcher to be used if a global command is executed (e.g. no tasks
   * are defined). A tasks.json file can either contain a global problemMatcher
   * property or a tasks property but not both.
   */
  problemMatcher?: string | ProblemMatcher | (string | ProblemMatcher)[];

  /**
   * The configuration of the available tasks. A tasks.json file can either
   * contain a global problemMatcher property or a tasks property but not both.
   */
  tasks?: TaskDescription[];
}

基本任务中的tasks就是可选任务组,可见可选任务组tasks是基本任务下的一个可选的配置项,其类型为TaskDescription类型的一个数组,下面是TaskDescription的官方定义。

/**
 1. The description of a task.
 */
interface TaskDescription {
  /**
 2. The task's name
   */
  label: string;

  /**
 3. The type of a custom task. Tasks of type "shell" are executed
 4. inside a shell (e.g. bash, cmd, powershell, ...)
   */
  type: 'shell' | 'process';

  /**
 5. The command to execute. If the type is "shell" it should be the full
 6. command line including any additional arguments passed to the command.
   */
  command: string;

  /**
 7. Whether the executed command is kept alive and runs in the background.
   */
  isBackground?: boolean;

  /**
 8. Additional arguments passed to the command. Should be used if type
 9. is "process".
   */
  args?: string[];

  /**
 10. Defines the group to which this task belongs. Also supports to mark
 11. a task as the default task in a group.
   */
  group?: 'build' | 'test' | { kind: 'build' | 'test'; isDefault: boolean };

  /**
 12. The presentation options.
   */
  presentation?: PresentationOptions;

  /**
 13. The problem matcher(s) to use to capture problems in the tasks
 14. output.
   */
  problemMatcher?: string | ProblemMatcher | (string | ProblemMatcher)[];

  /**
 15. Defines when and how a task is run.
   */
  runOptions?: RunOptions;
}

本文主要介绍可选任务组tasks的相关配置,关于基本任务将在另外的博文中介绍。

三、TaskDescription的配置项详解

从官方文档可见,一个典型的TaskDescription元素包含多种属性,下面逐一介绍:

  1. label:字符串类型,任务名,必选项;
  2. type:任务类型,有3个可选值’shell’ 、‘process’、‘cppbuild’,其中前2个是vscode中安装后即可提供的,‘cppbuild’是安装C++扩展之后支持的,估计如果安排其他语言的扩展,应该还有其他可选类型,关于取值的区别请参考老猿在CSDN的博文《信创之国产浪潮电脑+统信UOS操作系统体验5:visual studio code的任务配置文件tasks.json进行C++编译的任务配置类型type取值及含义》;
  3. command:任务需要执行的具体命令,可以是外部程序或shell命令,如对于C++编译任务,就可能是“gcc”;
  4. isBackground:是否后台运行,还是前台运行;
  5. args:命令执行的参数,相关案例《vscode中tasks.json文件使用的预定义变量及国产统信操作系统UOS下配置一个任务显示相关预定义变量的案例》;
  6. group:用于定义任务属于哪个组,其下子元素kind有3个可选值包括’build’ 、‘test’ 、‘none’,子元素isDefault为布尔类型,表示是否该任务为任务组的缺省任务。
    对于kind为’test’ 、‘none’的情况老猿没有深入研究,对kind为’build’的情况,当选择菜单:终端->运行生成任务 执行生成任务时:
    1>vscode查找是否存在有任务类型为‘build’的任务,如果有且只有一个,则执行该生成任务,否则转下步;
    2>查找是否有isDefault为true的任务,如果有且只有一个,则执行该任务,否则转下步;
    3>其他情况,vscode将列出所有类型为build的任务,由操作人员选择具体执行的任务。
  7. presentation: 用于控制终端面板窗口的输出信息展示,具体请参考老猿在CSDN的博文《Visual Studio Code tasks.json中控制任务执行问题面板显示内容的PresentationOptions介绍》的介绍;
  8. problemMatcher:用于控制任务执行时问题匹配及输出,具体请参考老猿在CSDN的博文《信创之国产浪潮电脑+统信UOS操作系统体验7:VSCode任务tasks.json的问题匹配器problemMatcher详解》的介绍;
  9. runOptions:用于控制任务怎么执行的可选配置项,这个配置项老猿没有进行相关验证测试,从官方说明可以看出包括以下子项:
    1>reevaluateOnRerun:布尔类型,控制通过“重新运行”命令执行任务时如何计算变量。默认值为“true”,表示重新运行任务时将重新评估任务变量。当设置为“false”时,将使用上次运行任务时解析的任务变量值;
    2>runOn:指定任务何时运行,有两个可选值,“default”表示只有通过“运行任务”命令执行任务时,才会运行任务,就是必须手动执行;“folderOpen”表示打开包含的文件夹时即开始运行该任务;
    3>instanceLimit:允许同时运行的任务实例数,默认值为1。

四、一个案例

下面是老猿配置的2个可选任务buildHello1和buildHello2的配置内容:

"tasks": [
    {
      "type": "cppbuild",
      "label": "buildHello1",
      "command": "/usr/bin/g++",
      "args": [
        "-fdiagnostics-color=always",
        "-g",
        "-Wall",
        "-Wextra",
        "-O0",
        "${workspaceFolder}/hello.cpp",
        "-o",
        "${fileDirname}/$hello1"
      ],
      "options": {
        "cwd": "${fileDirname}"
      },
      "problemMatcher": "$gcc",
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "detail": "编译器: /usr/bin/g++"
    },
    {
      "type": "cppbuild",
      "label": "buildHello2",
      "command": "/usr/bin/g++",
      "args": [
        "-fdiagnostics-color=always",
        "-g",
        "-Wall",
        "-Wextra",
        "-O0",
        "${workspaceFolder}/hello2.cpp",
        "-o",
        "${fileDirname}/$hello2"
      ],
      "options": {
        "cwd": "${fileDirname}"
      },
      "problemMatcher": "$gcc",
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "detail": "编译器: /usr/bin/g++"
    }]

配置完成后,在终端菜单选择“运行生成任务…”时可以看到两个任务供选择:
在这里插入图片描述

四、小结

本文介绍了tasks.json中任务配置选项的可选任务组tasks子配置项,tasks的类型是TaskDescription,文章介绍了TaskDescription的详细内容和用途。tasks配置项配置的任务是大多数任务的配置方式,理解相关子配置项的内容对于更好地配置vscode的任务有重要作用。

参考资料

  1. vscode用法;
  2. Additional information for Visual Studio Code tasks
  3. Variables Reference–Visual Studio Code supports variable
  4. Integrate with External Tools via Tasks
写博不易,敬请支持:

如果阅读本文于您有所获,敬请点赞、评论、收藏,谢谢大家的支持!

更多关于vscode任务配置的内容请参考专栏《国产信创之光》的其他文章。

关于老猿的付费专栏

  1. 付费专栏《https://blog.csdn.net/laoyuanpython/category_9607725.html 使用PyQt开发图形界面Python应用》专门介绍基于Python的PyQt图形界面开发基础教程,对应文章目录为《 https://blog.csdn.net/LaoYuanPython/article/details/107580932 使用PyQt开发图形界面Python应用专栏目录》;
  2. 付费专栏《https://blog.csdn.net/laoyuanpython/category_10232926.html moviepy音视频开发专栏 )详细介绍moviepy音视频剪辑合成处理的类相关方法及使用相关方法进行相关剪辑合成场景的处理,对应文章目录为《https://blog.csdn.net/LaoYuanPython/article/details/107574583 moviepy音视频开发专栏文章目录》;
  3. 付费专栏《https://blog.csdn.net/laoyuanpython/category_10581071.html OpenCV-Python初学者疑难问题集》为《https://blog.csdn.net/laoyuanpython/category_9979286.html OpenCV-Python图形图像处理 》的伴生专栏,是笔者对OpenCV-Python图形图像处理学习中遇到的一些问题个人感悟的整合,相关资料基本上都是老猿反复研究的成果,有助于OpenCV-Python初学者比较深入地理解OpenCV,对应文章目录为《https://blog.csdn.net/LaoYuanPython/article/details/109713407 OpenCV-Python初学者疑难问题集专栏目录 》
  4. 付费专栏《https://blog.csdn.net/laoyuanpython/category_10762553.html Python爬虫入门 》站在一个互联网前端开发小白的角度介绍爬虫开发应知应会内容,包括爬虫入门的基础知识,以及爬取CSDN文章信息、博主信息、给文章点赞、评论等实战内容。

前两个专栏都适合有一定Python基础但无相关知识的小白读者学习,第三个专栏请大家结合《https://blog.csdn.net/laoyuanpython/category_9979286.html OpenCV-Python图形图像处理 》的学习使用。

对于缺乏Python基础的同仁,可以通过老猿的免费专栏《https://blog.csdn.net/laoyuanpython/category_9831699.html 专栏:Python基础教程目录)从零开始学习Python。

如果有兴趣也愿意支持老猿的读者,欢迎购买付费专栏。

老猿Python,跟老猿学Python!

☞ ░ 前往老猿Python博文目录 https://blog.csdn.net/LaoYuanPython ░
tasks.json、launch.json、c_cpp_properties.json配置 【代码】tasks.json、launch.json、c_cpp_properties.json配置。 阅读详情

相关推荐

VS Code的tasks.json科普指南

- tasks.json是 VS Code 的系统配置文件,用于定义和管理各种自动化任务(如编译、测试、脚本执行等) - 当项目需要“在 VS Code 里一键执行命令”时就应投入 tasks.json,它能把工具链、调试、错误追踪串起来。

qq_34552942的博客 492

VScode 调试教程 tasks.json和launch.json的设置(超详细)

Linux环境下VSCode 调试教程 tasks.json和launch.json的设置

qq_59084325的博客 10万+

手工编辑 tasks.json 和 launch.json,让你的 VSCode 具备调试 .NET Core 程序的能力

如果 C# for Visual Studio Code 没有办法自动为你生成正确的 tasks.json 和 launch.json 文件,那么可以考虑阅读本文手工创建他们。 本文内容前期准备半自动创建 tasks.json 和 launch.json全手工创建 tasks.json 和 launch.json 前期准备 你需要安装 .NET Core Sdk、Visual Studio Co...

walterlv - 吕毅 8438

vscode任务配置之tasks.json

vscode配置任务

hutaotaotao的博客 1万+

Visual Studio Code配置C语言开发环境完整指南

Visual Studio Code(简称VSC)作为当前最受欢迎的轻量级代码编辑器之一,凭借其高度可定制性、丰富的插件生态以及跨平台支持能力,已成为C语言开发者的重要工具。然而,相较于集成度更高的IDE(如Visual Studio或Code::Blocks),VSC本身并不内置对C语言的编译与调试支持,必须通过合理的配置文件与外部编译器协同工作才能构建完整的开发环境。

weixin_28840811的博客 1998

QGroundControl高级配置与自定义功能实战指南

本文深入探讨了QGroundControl(QGC)的高级配置与自定义功能,为无人机开发者、系统集成商和高级用户提供实战指南。内容涵盖从品牌界面定制、自定义MAVLink消息处理,到插件开发与自动化部署的全流程,旨在帮助用户解锁QGC的隐藏潜力,打造专属的行业解决方案。

weixin_29234509的博客 247

Ubuntu 安装与使用 Visual Studio Code

1.Visual Studio Code简介 1.1.什么是Visual Studio Code? Visual Studio Code是微软推出的一个运行于 Mac OS X、Windows和 Linux 之上的,针对于编写现代 Web 和云应用的跨平台源代码编辑器。 1.2.主要功能 集成了所有一款现代编辑器所应该具备的特性,包括语法高亮(syntax high lighting),可定制的热...

LFJ骏 2万+

Altium Designer铺铜陷阱:为什么你的死铜总是清除不干净?

本文深入探讨Altium Designer中铺铜操作导致死铜无法清除的常见问题,分析死铜形成的五大诱因,并提供高级参数优化和网络连接性验证技巧。通过调整边界计算精度和泪滴算法设置,有效解决死铜残留问题,提升PCB设计质量与制造良率。

weixin_29169505的博客 366

Visual Studio Code中tasks.json全局任务命令选项CommandOptions配置介绍

本文介绍了Visual Studio Code中tasks.json全局任务命令选项CommandOptions的详细内容,并通过配置案例来说明CommandOptions各个子配置项的作用。

老猿Python 2385

Keystone变换(4)MATLAB仿真

关于Keystone变换三种方法(DFT-IFFT法、Sinc插值法和Chirp-Z法)的仿真

qq_45846079的博客 1574

从Unitree B2W到四足机器人:用Isaac Lab构建强化学习奖励函数的5个实战技巧

本文分享了在Isaac Lab仿真环境中,为Unitree B2W等四足机器人设计强化学习奖励函数的5个核心实战技巧。内容涵盖奖励函数的结构化组合、轮腿混合机器人的适配策略、课程学习的动态调整、域随机化增强鲁棒性以及高效的调试可视化方法,旨在帮助开发者构建更稳定、高效的机器人运动策略。

lg888的博客 1075

【工具-Visual Studio Code】

第一步:(点击设置)

sinat_23896491的博客 3114

通义千问语言模型Qwen2.5架构详解

此外,将基于API的模型 Qwen-Plus 与领先的专有和开源模型进行了对比,包括 GPT4-o、Claude-3.5-Sonnet、Llama-3.1-405B和DeepSeek-V2.5。Qwen2.5-Math-72B-Instruct的整体性能超越了Qwen2-Math-72B-Instruct和GPT4-o,甚至是非常小的专业模型如 Qwen2.5-Math-1.5B-Instruct也能在与大型语言模型的竞争中取得高度竞争力的表现。近来也出现了明显的转向小型语言模型(SLMs)的趋势。

搏博的专栏 1万+

vscode更改配置文件路径_Visual Studio Code安装和配置

Visual Studio Code编辑器在Windows上安装比较简单,直接setup.exe。安装好后首次启动配置插件,插件配置必须联网,从网上下载。如下图点击左侧扩展:首次安装会推荐一些常用插件。如果没有显示推荐的插件,点击左侧右上角的三个点按钮,会弹出列表,根据相应类别显示插件。想要安装插件,直接点击插进右侧的安装。VS Code自动下载并安装。安装位置在Windows的C:/Users/...

weixin_39908082的博客 1万+

DRAM自测试模块

1 背景技术DDR3/4 SDRAM属于高速外设,最高时钟频率可达到1600MHz,最高速率可达3200MT/s。在存储控制器与DDR34 SDRAM设备之间有一层专为高速接口设计的模拟电路,此电路对于前端设计人员来说,不管在模拟验证阶段和回片测试阶段,都是一个黑盒子。而对于后端测试人员来说若此部分为外购IP,则内部结构也是无法清楚了解的。所以在测试阶段,对于DDR34 SDRAM的测试就具有一定的

Hierro的DDR世界 7018

YOLOv11训练命令完全指南:从核心参数解析到高级调优实战(数据配置、epochs设定、batch-size优化与img-size调整)(二)

本文介绍了YOLOv11训练命令的完整配置与解析,提供了基础训练命令示例及参数详解。示例命令包含数据集配置(coco.yaml)、训练轮次(300)、批次大小(64)、图像尺寸(640)等核心参数,以及优化器(AdamW)、学习率(0.001)等调优选项。通过代码实现展示了训练器的初始化流程,包括参数解析、设备设置、数据加载和模型创建等关键步骤,为YOLOv11模型训练提供了实用指导。

本博客聚焦 YOLOv11 全流程落地,涵盖架构优化、数据集处理、训练技巧与多场景部署,兼及国产数据库、Java 开发与 AI 模型应用,内容兼顾理论与工程实践,为开发者提供系统干货,助力高效提升技术能力。 1110

Visual Studio Code 内置 Gulp 扩展:把 gulpfile.js 任务接入 VS Code Tasks 工作流

本文介绍 Visual Studio Code 官方仓库中随产品一起内置分发的 **Gulp 扩展**(位于 `extensions/gulp`)。它把项目中 `gulpfile.{js,ts}` 里定义的 Gulp 任务自动桥接到 VS Code 的 Tasks 系统中,让你无需打开终端就能通过 **任务(Tasks)菜单** 直接运行 build、compile、watch 等常规 Gulp

gitblog_00634的博客 406

《派出你的AI同事:WorkBuddy案例实战》062:投研资讯摘要与预警

投研资讯海量且时效性强,传统人工处理效率低、易遗漏。本文提出“投研资讯助理”四步法:多源解析(提取主体、事件、影响、时效)→ 摘要生成(三句话+关键数据)→ 预警分级(紧急/重要/关注+置信度)→ 分流推送。AI 7×24 小时值守,日均耗时从2小时降至10分钟,误报率显著降低。核心在于“解析准、摘要全、预警稳”,边界清晰:只提资讯与影响提示,不越权决策。建议分阶段上线,以误报归因持续优化规则,实现从“刷资讯”到“做决策”的跃迁。

LuckyHanMo的博客 197

Visual Studio Code 内置 Jake 构建任务支持详解:从 Jakefile.js 自动检测到 Tasks 集成

Jake 是 JavaScript 生态中经典的任务运行器(task runner),通过 `Jakefile.js` 声明任务。本文以 VS Code 源码仓库中内置的 [Jake 扩展](https://link.gitcode.com/i/692cede16bf0df17ace85cffd4c7a43a) 为对象,系统讲解它是如何把 Jake 任务自动检测并桥接为 VS Code Tasks

gitblog_01071的博客 460

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

深度学习工具包 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")

Visual Studio Code tasks.json中控制任务执行问题面板显示内容的PresentationOptions介绍

本文介绍了Visual Studio Code tasks.json中控制任务执行问题面板显示内容的PresentationOptions中的各元素的含义和使用方法,并举例说明了配置2个任务的presentation对输出的影响。

老猿Python 1968

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

Visual Studio Code运行 C/C++ 配置

使用visual studio code开发高度C/C++程序,需要配置tasks.json、launch.json和c_cpp_properties.json这三个文件(tasks.json : 编译器构建配置文件 ; launch.json : 调试器设置 配置文件 ; c_cpp_properties.json : 编译器路径和智能代码提示配置文件 )。

qq_42635198的博客 1446

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

信创之国产浪潮电脑+统信UOS操作系统体验8:Visual Studio Code中的任务文件tasks.json和任务配置要素介绍

本文介绍了Visual Studio Code中的任务文件tasks.json的任务(包括全局任务和局部可选任务)配置各要素的配置含义和用途,并举例说明了具体任务配置的应用,有助于大家深入理解vscode的任务配置方法。

老猿Python 1824

如何在Visual Studio Code 中运行 Python

1. 安装 Python 插件 进入主界面之后按Ctrl + p,输入:ext install python,下载第一个即可。  下载 Python 插件后即可在编写 Python 脚本时使用代码自动补全功能。 2. 设置 Python 运行 要在 Visual Studio Code 中运行 Python 代码需要修改 tasks.json 配

zhf_Joy的博客 4万+

信创之国产浪潮电脑+统信UOS操作系统体验5:visual studio code的任务配置文件tasks.json进行C++编译的任务配置类型type取值及含义

本文介绍了visual studio code的任务配置文件tasks.json的用途、支持的任务类型,进行C++编译的任务配置type参数取值可以是“cppbuild”、“shell”、“process”三种不同值,都能完成编译构建任务的执行,但是三者还是有所区别,最好的方式无疑是“cppbuild”。

老猿Python 2306

Upterm 项目实战:在 Visual Studio Code 中调试 Electron + TypeScript 终端模拟器

Upterm 是一款基于 Electron 与 TypeScript 构建的现代化终端模拟器(也是交互式 shell),其主进程与渲染进程分别由 Node.js 与 Chromium 执行。本文基于 [docs/vscodedebugging.md](https://link.gitcode.com/i/6497837941f3daefecc497d2743b2ec0) 提供的方法,完整讲解如何在

gitblog_00171的博客 976

Visual Studio Code安装教程

这个tasks.json文件定义了一个名为"C Compile"的任务,它使用gcc编译器来编译当前打开的C文件,并在项目目录下的bin文件夹中生成同名的可执行文件(.exe后缀主要用于Windows)。"program": "${fileDirname}/bin/${fileBasenameNoExtension}.exe", // 调试程序路径,与 tasks.json 中的输出一致。"label": "C Compile", // 任务名称,稍后在 launch.json 中会引用。

2302_78160524的博客 1696
上一篇: Visual Studio Code tasks.json中控制任务执行问题面板显示内容的PresentationOptions介绍
下一篇: Visual Studio Code中tasks.json全局任务命令选项CommandOptions配置介绍
LaoYuanPython
LaoYuanPython 2020年博客之星Top3 2020年博客之星Top3 领域专家: Python技术领域 领域专家: Python技术领域
博客等级 码龄8年 15万+粉丝 1324原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

打赏作者

LaoYuanPython

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

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

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

打赏作者

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

抵扣说明:

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

余额充值
⌂ 换网址