github上刚用hexo搭好博客,然后就发现GitHub.io被墙了,悲剧

如何使用github/hexo发布博客(新) 前言 这篇文章从hexo的介绍开始到真正通过自己的域名访问自己的博客网站,之后可能会逐渐把中心放到个人资源的积累上,现在网站刚开始搭建,之后可能会引用新的框架所以目前只是发展中,好处在于这篇教程对新手应该是很友好的,最后欢迎访问我的第一个域名lishinho.top,开始我们的网站部署吧! 目录 前言 一,什么是hexo 二,部署之前的准备 三,如何使用github/hexo发布博客 ... 阅读详情

前两天刚刚在github上用hexo搭好博客,还没开始写文章,就哗啦啦的遇到了GitHub.io被伟大的祖国墙了~~~

我这运气也是够可以的


好吧,把最新的搭建过程贴在这里吧,权当备份了


%% 要点如下


curl -sL https://deb.nodesource.com/setup_8.x | sed "s/exec_cmd \('apt-get update'\)/exec_cmd_nobail \1/g" |  sudo -E bash -
sudo apt-get install -y nodejs

sudo npm install -g cnpm --registry=https://registry.npm.taobao.org
sudo chown -R $USER:$(id -gn $USER) ~/.config
sudo chown -R $USER /usr/lib/node_modules
cnpm install -g hexo-cli

cd ~
git clone git@github.com: yourname / yourname .github.io.git
cd  yourname .github.io.git

cnpm install hexo-deployer-git --save
git config --global user.email "yourname@gmail.com"
git config --global user.name "yourname"

cnpm install hexo-renderer-jade@0.3.0 --save
cnpm install hexo-renderer-sass --save







hexo clean
hexo d -g



%% 以下是 详细的过程

## 安装nodejs

wget -qO- https://raw.github.com/creationix/nvm/master/install.sh | sh
nvm install stable


  • curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -


> 由于 apt-get update 失败,上述命令执行失败,改用下述方式:
1、wget https://deb.nodesource.com/setup_8.x
2、注释掉其中的 exec_cmd 'apt-get update'
3、sudo bash setup_8.x


ld@SPEEDOOPS-LAPTO:~$ apt-cache show nodejs |grep -i version
Version: 8.1.0-1nodesource1~trusty1
Version: 0.10.25~dfsg2-2ubuntu1

  • sudo apt-get install -y nodejs


ld@SPEEDOOPS-LAPTO:~$ sudo apt-get install nodejs
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  nodejs
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 12.5 MB of archives.
After this operation, 64.3 MB of additional disk space will be used.
Fetched 12.5 MB in 10s (1,227 kB/s)
Selecting previously unselected package nodejs.
(Reading database ... 24973 files and directories currently installed.)
Preparing to unpack .../nodejs_8.1.0-1nodesource1~trusty1_amd64.deb ...
Unpacking nodejs (8.1.0-1nodesource1~trusty1) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Setting up nodejs (8.1.0-1nodesource1~trusty1) ...

ld@SPEEDOOPS-LAPTO:~$ nodejs --version
v8.1.0

  • 测试nodejs

ld@SPEEDOOPS-LAPTO:~$ nodejs hello-node.js
服务器运行在 http://127.0.0.1:3000/

ld@SPEEDOOPS-LAPTO:~$ cat hello-node.js
const http = require('http');

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World\n');
});

server.listen(port, hostname, () => {
  console.log(`服务器运行在 http://${hostname}:${port}/`);
});

## github创建工程:blog


Head over to  GitHub and  create a new repository named  username.github.io, where  username is your username (or organization name) on GitHub.

git clone https://github.com/ username/ username.github.io

cd  username.github.io
echo "Hello World" > index.html

git add --all
git commit -m "Initial commit"
git push -u origin master

Fire up a browser and go to  http:// username .github.io.



## SSH Key


ssh-keygen -t rsa -b 4096 -C "peter.liude@gmail.com"
生成ssh key,密码navi@123

在个人设置中新建SSH Key,贴入 cat ~/.ssh/id_rsa.pub 的内容

添加完成后再次执行git clone就可以成功克隆github上的代码库了。


## 安装hexo




npm uninstall -g hexo-cli
npm install -g hexo-cli
npm list hexo
npm list -g


request to https://registry.npmjs.org/npm failed, reason: connect EAGAIN

sudo npm install -g cnpm --registry=https://registry.npm.taobao.org


cnpm install -g hexo-cli


 npm update check failed
 sudo chown -R $USER:$(id -gn $USER) /home/ld/.config

Error: EACCES: permission denied, mkdir '/usr/lib/node_modules/hexo-cli_tmp'
sudo chown -R $USER /usr/lib/node_modules
cnpm install -g hexo-cli

 sudo ln -s /usr/lib/node_modules/hexo-cli/bin/hexo /usr/bin/hexo
hexo -v


## 

hexo init blog
cd blog
npm install
hexo generate
hexo server


  • 更换主题

git clone https://github.com/tufu9441/maupassant-hexo.git themes/maupassant

cnpm install hexo-renderer-jade@0.3.0 --save
cnpm install hexo-renderer-sass --save



编辑Hexo目录下的  _config.yml ,将 theme 的值改为 maupassant 。

* 部署

vim _config.yml, 翻到最下面,改成我这样子的
deploy:
  type: git
  repository: https://github.com/speedoops/speedoops.github.io.git
  branch: master


npm install hexo-deployer-git --save
git config --global user.email "peter.liude@gmail.com"
git config --global user.name "Speedoops"


$ hexo deploy

hexo clean && hexo g && hexo d
hexo new "postName" #新建文章
hexo new page "pageName" #新建页面
hexo generate #生成静态页面至public目录
hexo server #开启预览访问端口(默认端口4000,'ctrl + c'关闭server)
hexo deploy #将.deploy目录部署到GitHub
hexo help  # 查看帮助
hexo version  #查看Hexo的版本

hexo g == hexo generate

hexo d  ==  hexo deploy
hexo s  ==  hexo server
hexo n  ==  hexo new
hexo d -g





  1. Enter passphrase for key '/home/qingxu/.ssh/id_dsa':   
仍然需要你输入私钥。而且以后不管你登陆几次,都会提醒你输入私钥,没有达到我们的要求,怎么办呢?

ssh-agent是用于管理密钥,ssh-add用于将密钥加入到ssh-agent中,SSH可以和ssh-agent通信获取密钥,这样就不需要用户手工输入密码了。

eval `ssh-agent`
ssh-add
Enter passphrase for /home/qingxu/.ssh/id_dsa: 

不过由于每次登录都需要设置一次,所以最好将命令放到~/.bash_profile中。

另外,可以采用keychain来处理这一步,参考:

http://www.ibm.com/developerworks/cn/linux/security/openssh/part1/index.html



Markdown编辑器





如何在Hexo博客上使用畅言评论插件?


多说宣称要进行业务转型,自然评论系统也要关闭,国内的目前比较好的评论系统只有畅言不错,但是畅言需要备案,而我不愿意备案,无奈只能选Disqus了,所以将本站点的多说评论转成Disqus了。




选择Hexo还是Jekyll

于是开始接触比较流行的一些静态博客框架,比较流行的有Jekyll,Hexo,Simple,Octopress,Pelican以及Lo·gecho等等。这些静态程序可以说都有各自的好处,但最后我选择了Hexo来搭建自己的博客,和Jekyll相比,选择Hexo主要原因是:

  1. Jeky基于Ruby实现,安装Jeky需要搭建Ruby环境,在Windows搭建Ruby环境并不是被推荐的,而 Hexo基于NodeJs实现,在Windows上安装NodeJs开发环境简单。
  2. Jekyll没有本地服务器,无法实现本地博文预览功能,需要上传到WEB容器中才能预览功能,而Hexo可以通过简单的命令实现本地的预览,并直接发布到WEB容器中实现同步。
  3. 比较直接的另一个原因是在网上查找了很多博客的主题,发现Jekyll官网提供的主题都不怎么好看(可能是个人原因),而Hexo的主题看的比较顺眼。
  4. 两者都支持Markdown语法,这点我非常喜欢。



hexo博客从github迁移到gitee gitee感觉做的不错,而且是国内的,速度要比github快不少。所以将博客从github迁移到gitee。 1.在gitee.com修改个性地址: 比如这里最后是tommy88。 2.在gitee.com创建一个public项目,名称为上面的tommy88. 3.打开git bash,进入到博客目录。 在git Bash中,输入: ssh-keygen -t rsa... 阅读详情

相关推荐

用Github桌面版实现最简单的hexo部署到Github.io

今天准备把hexo部署到github.io的时候参考了网上几篇文章,发现写的都十分地费劲,不是老是出错,就是步骤麻烦,特地写一篇来记录一下我的方法,当然,这篇文章是建立在在本地已经写好hexo的情况下的 首先,下载github桌面版地址如下:GitHub桌面版 嗯 做完这一步之后,再github上创建项目(这一步大家应该都已经做完了,没做完的话可以参考一下这里Github.io第二步,用gith

气派的欠账包店 2751

使用Github.io创建自己的博客

导致这个空格出现的原因是,在添加知乎和csdn的链接后,在VScode中进行了保存,保存时默认对html文件进行了格式化,自动添加了这个空格。如果是直接fork了原项目,那么这个项目是无法修改可见性为私密的。主要就是name,baseurl和description个人描述等的修改,这里就不赘述了。基本了解文件结构之后,想要再改什么,就直接参考下面这两个成品改就可以了。可知,一般5~10分钟就发布好了,但是实际上,查看。720的png图像,因此自己的图像也尽量是720。中,后者当做备份,然后对前者进行修改。

啷个哩个啷 2万+

Hexo+Github 搭建属于自己的博客

个人博客界面: 首先呢,先说一下吧,作为一个程序猿来说,大多的大牛都是使用的是msdn/github这些来交流技术,但是我后来发现csdn上面好多的大牛都已经摒弃csdn,自己搭建个人博客进行发表文章记录点滴了。 虽然说我不会放弃csdn,因为已经养成了习惯了,但是还是想拥有一个自己的博客,那是因为这是一种信仰。 今天呢,花了一天的时候,研究了一下,颇有收获。 搭建个人博客=域名(...

一只IT小小鸟 2727

在GitHub上如何创建github.io

在GitHub上如何创建github.io github网址:https://github.com/ 具体实现: 第一步:先创建一个gitthub账号,进入如下页面: 第二步:点击new这个按钮:

yycnf的博客 1万+

Hexo搭建github.io个人博客时出现的问题

今天想要和你们分享一些关于搭建个人博客之中出现的一些问题。。。我也是费了一些功夫,第一次接触这个好多东西也是懵懵懂懂,,走了不少弯路,各种问题都有。。。。我使用的是Hexo+node.js+git的方式快速搭建的博客,具体搭建过程传送门:Hexo+Nodejs+git快速搭建github.io个人博客 反反复复的删除仓库在部署一次次的调试终于完工哈哈哈是个滋味,,,好了不废话了,直接进入正题 1...

关注我~分享更多技术干货 901

hexo+github教程之二:hexo博客发布到github

上一篇教程已经把hexo博客安装好在本地了,但是只能在本地访问,现在我们要将博客部署到github上。一、github注册及配置1、首先我们先去准备github ,(点击文字进行跳转)。 2、首先在主界面注册github进行!按照步骤进行注册。 3、注册成功先不要急!此时我们还需要验证邮箱地址。 4、接下来我们需要建立一个仓库。 记住建立仓库时所填写的内容!是你的帐号.github.io

水下看花 1546

【GitHub.io/Github Pages使用教程】从头开始搭建自己的Github Pages,打造个人博客网站,展示个人简历、项目、文档或想要与世界共享的任何其他内容

【Github Pages使用教程】从头开始搭建自己的Github Pages,打造个人博客网站,展示个人简历、项目、文档或想要与世界共享的任何其他内容 GitHub Pages:Websites for you and your projects. GitHub Pages 允许您将 GitHub 仓库转换为网站,展示您的简历、项目、文档或您想要与世界共享的任何其他内容。这里有创建github.io的教程,会使用git命令来上传文件至GitHub仓库,相对较为复杂些。......

Xminyang的博客 8325

github.io创建个人网站

github.io是 GitHub 提供的免费 Pages服务,不需要购买云服务器和域名,就可以将自己的项目、博客在互联网上进行共享。

Cachel Wood的博客 5943

Hexo+Github搭建个人博客教程

完全免费的搭建个人博客,没有任何收费,零基础小白也能上手,不需要编程基础,跟着操作来即可。首先要了解一下我们搭建博客要用到的框架。Hexo是高效的静态站点生成框架,它基于Node.js。通过Hexo,你可以直接使用Markdown语法来撰写博客。相信很多小伙伴写工程都写过README.md文件吧,对,就是这个格式的!写完后只需两三条命令即可将生成的网页上传到你的github上,然后别人就可以看到你的网页啦。是不是很简单?你无需关心网页源代码的具体细节,你只需要用心写好你的博客内容就行。

Rockivy的博客 4944

【亲测解决】hexo搭建Github博客上传后,访问网页显示404问题解决方案

在搭建Hexo的时候进行到 hexo clean hexo generate hexo deploy 这里的时候就需要去访问githubUsername.github.io这个域名了,但是可能会有同学发现访问的时候是404.这个时候一般有两种原因,我们分别讲解 1.你的github上的项目名字新建有误 创建一个和你用户名相同的仓库,后面加.github.io,只有这样,将来要部署到GitHub ...

诺浅的专栏 2万+

hexo+GitHub搭建个人博客前期安装部署

现在有很多更新博客的平台,但是会受到各种限制,关键词限制、广告限制等等。其实搭建一个自己个人博客也是非常好的选择,相对来说比较自由。自己购买域名和服务器的话,搭建成本相对较高,而且还需要定期维护,显然对我们个人来说不是很合适。 还有一种很好的选择就是通过hexo博客框架,在GitHub平台托管我们的博客,这种方式不需要定期维护,十分舒服。

静Yu的博客 2413

GitHub+Hexo搭建个人博客 - 详细教程

在本地typora写好一篇笔记后,上传到博客上,会发现图片显示不出来,因为笔记中的图片地址指向本机电脑,上传到博客之后,自然就无法显示了。https://github.com/用户名/repository仓库名/raw/分支名main/图片文件夹名称/.png or.jpg。,Hexo框架和以后自己发布的网页都在这个文件夹中。创建好后,进入文件夹中,按住shift键,右击鼠标点击命令行。git config --global user.email "你的GitHub注册邮箱"

lang_xw的博客 4101

电价预测的Transformer实战:从注意力机制到超长序列建模

本文深入探讨了Transformer模型在电价预测领域的实战应用,对比了其与LSTM在处理长序列依赖和误差累积问题上的优劣。文章详细解析了自注意力机制的原理,并提供了处理超长序列的位置编码方法、构建专用预测模型的完整PyTorch代码,以及防止信息泄露的关键技巧。通过实战对比,展示了Transformer在并行计算、长距离建模和预测精度上的显著优势,并分享了应对极端波动和提升模型效率的高级优化策略。

f6g7h8i9j的博客 540

用hexo+github搭建个人博客

需要先安装 Node.js 和 Git。Node.js 包含了 npm(Node Package Manager),用于安装 Hexo 及其插件;Git 则用于部署博客到远程仓库。

weixin_62735356的博客 1812

【脑电分析系列】第15篇:脑电功能连接性与脑网络分析(二):Granger因果性、图论指标与复杂网络构建

摘要: 本文深入探讨了脑电(EEG)分析中的高阶连接性方法——有效连接(Effective Connectivity),重点介绍了Granger因果性(Granger Causality, GC)的原理与应用。GC通过统计预测揭示脑区间信息流动方向,超越了传统功能连接的同步性分析。文章还结合图论指标(如度、路径长度、聚类系数和模块化)量化脑网络的拓扑结构,并通过Python代码(MNE和NetworkX库)演示了从EEG数据构建、分析复杂脑网络的完整流程。该研究为理解大脑动态互动、认知任务信息流及神经系统疾

qq_32516809的博客 1560

【Stata双重差分模型】双重差分DID的具体操作步骤

本案例将详细阐述如何使用双重差分法进行实证分析,并展示具体的STATA操作代码。

a519573917的博客 2万+

关于hexo更新到GitHub后博客内容未变问题

关于更新到GitHub后博客内容未变问题 网站修改和更新文章后,在本地用 hexo s 部署到了GitHub后却发现自己的博客网站内容没有变化。找了一中午终于找到了原因所在。 最开始更新完毕确认检查后,使用 hexo d 已经部署到了github,自己在github上也看到确实已经更新到了仓库,但是博客内容却一直没变。百度了下说是会有一段时间的延迟。但是等了一个晚上发现内容还是没有更新。于是又看了下GitHub的仓库,在右侧边栏发现了这个东西: 都知道github-pages是GitHub自带生成静态

Lu_xiuyuan的博客 9315

基于Python的虚拟货币社区情绪分析与市场价格预测爬虫实现

本文探讨了如何利用Python爬虫技术获取虚拟货币社区数据,并通过情感分析预测市场价格走势。我们将使用最新的异步爬虫框架、自然语言处理技术和机器学习模型,构建一个完整的社区情绪分析系统。本文提供了详细的代码实现和理论解释,适合作为毕业设计参考。关键词:Python爬虫、虚拟货币、情感分析、价格预测、异步爬虫、机器学习爬虫框架aiohttp和httpx用于异步HTTP请求HTML解析和parsel数据存储MongoDB和Pandas用于数据处理自然语言处理库和VADER情感分析工具机器学习和。

2201_76125261的博客 521

GitHub+Hexo博客搭建及优化

优快云仅用于增加百度收录权重,排版未优化,日常不维护。请访问:www.hceng.cn 查看、评论。 本博文对应地址: https://hceng.cn/2017/03/06/GitHub+Hexo搭建及优化/ 本文主要是记录本博客的搭建和优化。 为什么做独立博客? 我想大概就是激励自己去持续学习和思考。 首先说下本博客搭建的大致流程: 1.有一个GitHub账号,同时配置GitHub ...

hceng_linux 1845

第1集:面试官视角:AIOps 核心能力模型与面试项目全局搭建【免费试读】

本文介绍了一门面向AIOps工程师的面试实战课程,针对当前运维领域薪资差距明显的痛点,帮助学员系统掌握企业级AIOps平台开发能力。课程承诺提供可直接用于面试和生产环境的代码实现,从零构建模块化AIOps平台。第一集重点讲解了面试官视角下的核心能力模型,并指导学员搭建项目基础环境,包括Python虚拟环境配置、本地大模型部署(Ollama)以及智能巡检Agent的代码实现。课程强调实战导向,通过40集系统讲解,帮助学员实现薪资40-60万的职业跃升。

qq_2937655951的博客 615

锂电池的充电和放电曲线解读

锂电池充放电曲线是反映其性能的关键指标。充电曲线分为恒流和恒压两阶段:恒流阶段电压快速上升,恒压阶段电流逐渐降低;放电曲线则呈现平台期和快速衰减期特征。这些曲线受温度、充放电倍率及材料体系(如三元锂或磷酸铁锂)显著影响。通过分析曲线特征,可优化电池管理系统,实现精准的SOC估算、快充策略制定及故障诊断,从而在电池性能与安全性间取得平衡。不同应用场景(如新能源汽车或消费电子)对曲线形态有特定要求。

start_up_go的博客 5066

【Hexo + Github 搭建自己的专属博客】

在Windows上使用Git,可以从Git官网直接,然后按默认选项安装即可。安装完成后,在开始菜单里找到,蹦出一个类似命令行窗口的东西,就说明Git安装成功!在Git中绑定Github账号,打开“Git Bash”,在命令框中依次输入两行命令:由于Hexo是基于Node.js驱动的一款博客框架,所以安装NodeJSoad/并配置环境变量。以上环境准备好了就可使用npm开始安装Hexo安装Hexo完成后,在指定文件夹下打开。

2301_76761656的博客 1848

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

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

搭建hexo+Github博客

搭建hexo-Github博客 摘要 本文主要向大家介绍了如何搭建hexo-Github博客的详细过程,有需要的朋友们可以尝试阅读,希望对大家有帮助。 简要吐槽 搭博客其实没那么麻烦,但是在网上各类教程的“指导下”,我不知道放弃了多少次又重新试了多少次,大部分还是得靠自己。。。今天在这里给大家简要分享一下我搭博客(hexo-Github)的教程,基于自己很多很多日日夜夜的尝试与摸索后的经验教训,希望对大家有一些帮助。 直入主题 准备工作 首先需要三个工具,git、npm、node.js。可以在win

qq_43780964的博客 1万+

IMSL CNL 7.0.0 (x86-64)Crack

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

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

快速搭建hexo博客并部署到github

前提: 一般我们在学习了一段时间后,一般会想弄一个博客去写文章,别人在网上可以访问。自己写博客底层框架太久,所以这里用hexo博客框架快速生成自己的博客,自己只管写文章和魔改就行。 实现: 1.安装node.js和git: 去下载就好,下载完就默认安装~ 链接: node.js git 安装就不过多阐述了~ 2.出现版本号就是安装好了 在cmd里面输入: node -v npm -v 3.下载hexo框架: 继续在cmd里输入以下: npm install -g hexo-cli 回车然后等待安

你好呀,很高兴你在看这里~ 2453

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

上一篇: Windows调测技巧文章汇总
下一篇: hexo博客源码备份与恢复
speedoops
博客等级 码龄16年 33粉丝 6原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值