海萤物联网教程:Python SDK

go语言的使用方法 【1】搭建Go开发环境-安装和配置SDK1).SDK的全称(Software Development Kit软件开发工具包)2).SDK是提供给开发人员使用的,其中包含了对应的开发语言的工具包。【2】.SDK下载1).Go语言的官网为:golang.org无法访问,需要翻墙请注意:安装路径不要有中文或者特殊符号如空格等SDK安装目录建议:一般我安装在d:golang安装时,基本上是傻瓜式安装,解压可以使用一定要注意看版本号哦,不然会下错的哦。 阅读详情

海萤物联网教程:Python SDK

本文博客链接:http://blog.csdn.net/jdh99,作者:jdh,转载请注明.

在线文档地址

简介

此SDK适用于Python3.5及以上版本。使用此SDK可以让节点连接海萤物联网,与其他节点通信。节点可以是终端设备,也可以是个人电脑上的程序,可以使用此SDK与其他节点通信,并可以以服务的形式开放自己的能力。

Python SDK是海萤物联网的SDK之一,主要有如下功能:

  • 连接海萤物联网
  • 与其他节点通信
  • 以服务的形式开放节点自身的能力

特点

基于此SDK可以极大降低物联网的开发门槛,可以实现:

  • 一行代码连接网络
  • 一行代码开放服务
  • 一行代码通信

开源

安装

pip install tziot

背景知识

API

def bind_pipe_net(ia: int, pwd: str, ip: str, port: int) -> int:
    """ 绑定网络管道.绑定成功后返回管道号"""
    
def bind_pipe(ia: int, send, is_allow_send) -> int:
    """
    绑定管道.绑定成功后返回管道号
    :param ia: 设备单播地址
    :param send: 发送函数.格式:func(dst_pipe: int, data: bytearray)
    :param is_allow_send: 是否允许发送函数.格式:func() -> bool
    :return: 管道号
    """

def pipe_receive(pipe: int, data: bytearray):
    """管道接收.pipe是发送方的管道号.如果是用户自己绑定管道,则在管道中接收到数据需回调本函数"""

def is_conn() -> bool:
    """是否连接核心网"""

def call(pipe: int, dst_ia: int, rid: int, timeout: int, req: bytearray) -> (bytearray, int):
    """
    RPC同步调用
    :param pipe: 通信管道
    :param dst_ia: 目标ia地址
    :param rid: 服务号
    :param timeout: 超时时间,单位:ms.为0表示不需要应答
    :param req: 请求数据.无数据可填bytearray()或者None
    :return: 返回值是应答字节流和错误码.错误码非0表示调用失败
    """

def register(rid: int, callback):
    """
    注册DCOM服务回调函数
    :param rid: 服务号
    :param callback: 回调函数.格式: func(pipe: int, src_ia: int, req: bytearray) (bytearray, int)
    :return: 返回值是应答和错误码.错误码为0表示回调成功,否则是错误码
    """

def config_core_param(ia: int, ip: str, port: int):
    """配置核心网参数"""

def config_dcom_param(retry_num: int, retry_interval: int):
    """
    配置dcom参数
    :param retry_num: 重发次数
    :param retry_interval: 重发间隔.单位:ms
    """

默认参数

当前默认的参数:

参数值
DCOM重发次数5
DCOM重发间隔500ms

调用config_core_param函数可以修改DCOM参数。

config_core_param函数可以修改海萤物联网平台默认地址,使用默认值即可,不需要调用函数修改。

绑定管道

tziot包中封装了dcom包,在绑定管道时会初始化DCOM。

tziot中调用bind_pipe函数可以绑定自定义管道,如果使用自定义管道,则需应用中调用pipe_receive函数将接收到的数据发送给tziot包。

绑定网络管道是绑定管道的一个特例,如果节点可以直接连接互联网(比如使用以太网或者wifi),则调用bind_pipe_net函数即可,不需要使用bind_pipe函数和pipe_receive函数。

  • 示例:绑定网络管道,节点地址是0x2140000000000101,本地端口号是12021
pipe = bind_pipe_net(0x2140000000000101, pwd, "0.0.0.0", 12021)

返回的是管道号pipe。后续使用call函数与其他节点通信,需要使用此管道号。

绑定管道后sdk会自动连接海萤物联网,可以调用is_conn函数查看连接是否成功。

注册服务

节点可以通过注册服务开放自身的能力。

def register(rid: int, callback):
    """
    注册DCOM服务回调函数
    :param rid: 服务号
    :param callback: 回调函数.格式: func(pipe: int, src_ia: int, req: bytearray) (bytearray, int)
    :return: 返回值是应答和错误码.错误码为0表示回调成功,否则是错误码
    """

注册函数中,每个服务号(rid),都可以绑定一个服务。

  • 示例:假设节点2140::101是智能插座,提供控制和读取开关状态两个服务:
tziot.register(1, control_service)
tziot.register(2, get_state_service)


def control_service(pipe: int, src_ia: int, req: bytearray) -> (bytearray, int):
	"""控制开关服务.返回值是应答和错误码.错误码为0表示回调成功,否则是错误码"""
	if req[0] == 0:
		off()
	else:
		on()
	return None, dcom.SystemOK


def get_state_service(pipe: int, src_ia: int, req: bytearray) -> (bytearray, int):
	"""读取开关状态服务.返回值是应答和错误码.错误码为0表示回调成功,否则是错误码"""
	return bytearray([state()]), dcom.SystemOK

调用目的节点服务

def call(pipe: int, dst_ia: int, rid: int, timeout: int, req: bytearray) -> (bytearray, int):
    """
    RPC同步调用
    :param pipe: 通信管道
    :param dst_ia: 目标ia地址
    :param rid: 服务号
    :param timeout: 超时时间,单位:ms.为0表示不需要应答
    :param req: 请求数据.无数据可填bytearray()或者None
    :return: 返回值是应答字节流和错误码.错误码非0表示调用失败
    """

同步调用会在获取到结果之前阻塞。节点可以通过同步调用,调用目标节点的函数或者服务。timeout字段是超时时间,单位是毫秒。如果目标节点超时未回复,则会调用失败。如果超时时间填0,则表示不需要目标节点回复。

  • 示例:2141::102节点控制智能插座2141::101开关状态为开
resp, errCode = tziot.call(1, 0x2140000000000101, 3000, bytearray([1]))
  • 示例:2141::102节点读取智能插座2141::101开关状态
resp, errCode = tziot.call(2, 0x2140000000000101, 3000, None)
if errCode == dcom.SystemOK:
	print("开关状态:", resp[0])

请求和应答数据格式

建议使用结构体来通信。详情可参考: 海萤物联网教程:物联网RPC框架Python DCOM 中的数据格式章节。

完整示例

示例以与海萤物联网中的python版本的ntp服务通信为例。

python版本的ntp服务器开源地址

ntp服务介绍

python版本的海萤物联网ntp服务上线

ntp服务器地址:

0x2141000000000405

当前提供两个服务:

服务号服务
1读取时间1
2读取时间2.返回的是结构体
读取时间服务1
  • CON请求:空或者带符号的1个字节。

当CON请求为空时,则默认为读取的是北京时间(时区8)。

也可以带1个字节表示时区号。这个字节是有符号的int8。

小技巧,可以使用0x100减去正值即负值。比如8对应的无符号数是0x100-8=248。

  • ACK应答:当前时间的字符串

当前时间字符串的格式:2006-01-02 15:04:05 -0700 MST

读取时间服务2.返回的是结构体
  • CON请求:格式与读取时间服务1一致

  • ACK应答:

struct {
    // 时区
    uint8 TimeZone
    uint16 Year
    uint8 Month
    uint8 Day
    uint8 Hour
    uint8 Minute
    uint8 Second
    // 星期
    uint8 Weekday
}

开放服务示例

"""
Copyright 2021-2021 The jdh99 Authors. All rights reserved.
网络校时服务
Authors: jdh99 <jdh821@163.com>
"""

import config

import tziot
import dcompy as dcom
import lagan
import sbc

from datetime import datetime, timedelta

TAG = 'ntp'

# 应用错误码
# 内部错误
ERROR_CODE_INTERNAL_ERROR = 0x40
# 接收格式错误
ERROR_CODE_RX_FORMAT = 0x41

# rid号
# 读取时间.返回的是字符串
RID_GET_TIME1 = 1
# 读取时间.返回的是结构体
RID_GET_TIME2 = 2


class AckRidGetTime2(sbc.LEFormat):
    _fields_ = [
        # (字段名, c类型)
        # 时区
        ('time_zone', sbc.c_uint8),
        ('year', sbc.c_int16),
        ('month', sbc.c_uint8),
        ('day', sbc.c_uint8),
        ('hour', sbc.c_uint8),
        ('minute', sbc.c_uint8),
        ('second', sbc.c_uint8),
        # 星期
        ('weekday', sbc.c_uint8),
    ]


def main():
    config.init()

    lagan.load(0)
    lagan.set_filter_level(lagan.LEVEL_INFO)
    lagan.enable_color(True)
    dcom.set_filter_level(lagan.LEVEL_WARN)

    tziot.bind_pipe_net(config.LOCAL_IA, config.local_pwd, config.LOCAL_IP, config.LOCAL_PORT)
    tziot.register(RID_GET_TIME1, ntp_service1)
    tziot.register(RID_GET_TIME2, ntp_service2)


def ntp_service1(pipe: int, src_ia: int, req: bytearray) -> (bytearray, int):
    """校时服务.返回值是应答和错误码.错误码为0表示回调成功,否则是错误码"""
    ip, port = dcom.pipe_to_addr(pipe)

    if len(req) == 0:
        time_zone = 8
    elif len(req) == 1:
        time_zone = req[0]
        if time_zone >= 0x80:
            time_zone = -(0x100 - time_zone)
    else:
        lagan.warn(TAG, "ip:%s port:%d ia:0x%x ntp failed.len is wrong:%d", ip, port, src_ia, len(req))
        return None, ERROR_CODE_RX_FORMAT

    now = datetime.utcnow() + timedelta(hours=time_zone)
    if time_zone >= 0:
        s = '%04d-%02d-%02d %02d:%02d:%02d +%02d00 MST' % (now.year, now.month, now.day, now.hour, now.minute,
                                                            now.second, time_zone)
    else:
        s = '%04d-%02d-%02d %02d:%02d:%02d -%02d00 MST' % (now.year, now.month, now.day, now.hour, now.minute,
                                                            now.second, -time_zone)
    lagan.info(TAG, 'ip:%s port:%d ntp time:%s', ip, port, s)
    return tziot.str_to_bytearray(s), 0


def ntp_service2(pipe: int, src_ia: int, req: bytearray) -> (bytearray, int):
    """校时服务.返回值是应答和错误码.错误码为0表示回调成功,否则是错误码"""
    ip, port = dcom.pipe_to_addr(pipe)

    if len(req) == 0:
        time_zone = 8
    elif len(req) == 1:
        time_zone = req[0]
        if time_zone >= 0x80:
            time_zone = -(0x100 - time_zone)
    else:
        lagan.warn(TAG, "ip:%s port:%d ia:0x%x ntp failed.len is wrong:%d", ip, port, src_ia, len(req))
        return None, ERROR_CODE_RX_FORMAT

    now = datetime.utcnow() + timedelta(hours=time_zone)
    t = AckRidGetTime2()
    t.time_zone = time_zone
    t.year = now.year
    t.month = now.month
    t.day = now.day
    t.hour = now.hour
    t.minute = now.minute
    t.second = now.second
    t.weekday = now.isoweekday()
    lagan.info(TAG, 'ip:%s port:%d ntp time:%04d-%02d-%02d %02d:%02d:%02d +%02d00 MST', ip, port, t.year, t.month,
               t.day, t.hour, t.minute, t.second, t.time_zone)
    return t.struct_to_bytearray(), 0


if __name__ == '__main__':
    main()

读取时间服务1

节点2141::401读取ntp服务器的服务1,并打印时间字符串。

def main():
    pipe = tziot.bind_pipe_net(0x2141000000000401, pwd, '0.0.0.0', 12021)
    while not tziot.is_conn():
        pass
    resp, err = tziot.call(pipe, 0x2141000000000005, 1, 3000, bytearray())
    print(err, resp)
}

输出结果:

0 b'2021-04-03 16:48:50 +0800 MST'

读取时间服务2

ntp服务器的2号是结构体形式的时间。

import tziot
import sbc


class AckRidGetTime(sbc.LEFormat):
    _fields_ = [
        # (字段名, c类型)
        # 时区
        ('time_zone', sbc.c_uint8),
        ('year', sbc.c_int16),
        ('month', sbc.c_uint8),
        ('day', sbc.c_uint8),
        ('hour', sbc.c_uint8),
        ('minute', sbc.c_uint8),
        ('second', sbc.c_uint8),
        # 星期
        ('weekday', sbc.c_uint8),
    ]


def main():
    pipe = tziot.bind_pipe_net(0x2141000000000401, pwd, '0.0.0.0', 12021)
    while not tziot.is_conn():
        pass
    resp, err = tziot.call(pipe, 0x2141000000000005, 2, 3000, bytearray())
    if err != 0:
        return

    ack = AckRidGetTime()
    if not ack.bytearray_to_struct(resp):
        return
    print(ack.time_zone, ack.year, ack.month, ack.day, ack.hour, ack.minute, ack.second, ack.weekday)


if __name__ == '__main__':
    main()

输出结果:

8 2021 4 3 16 47 21 6
萤石开放平台接入摄像头 python调用摄像头 阅读详情

相关推荐

go语言sdk官网下载

go语言sdk,从官网下载的,国内不好找,希望有用

海萤物联网教程:Go SDK

文章目录海萤物联网教程:Go SDK简介特点开源安装背景知识API默认参数绑定管道注册服务调用目的节点服务请求和应答数据格式完整示例ntp服务器开源地址ntp服务介绍读取时间服务1读取时间服务2.返回的是结构体开放服务示例读取时间服务1读取时间服务2 海萤物联网教程:Go SDK 本文博客链接:http://blog.csdn.net/jdh99,作者:jdh,转载请注明. 欢迎前往社区交流:海萤物联网社区 简介 此SDK适用于Go 1.12.5版本及以上版本。使用此SDK可以让节点连接海萤物联网,与其他节

jdh99的专栏 613

海萤物联网IA申请器V1.0.zip

海萤物联网IA申请器V1.0.zip

Go语言的SDK是什么

SDK就是软件开发工具包

qq_39657769的博客 3838

Maya vray 3S皮肤材质球设置与材质节点连接

Maya vray 3S皮肤材质球设置与材质节点连接

WETQETF的博客 2703

HCLR-Net: 混合对比学习正则化与局部随机扰动用于水下图像增强

独特贡献在于开发了一种处理负样本的新策略,既保留了负样本的统计特性,又防止网络过度剖析这些样本中的特征信息。通过根据每个通道特征的重要性对模型进行加权,我们可以增强富含上下文信息的通道,从而获得更准确、更详细的特征表示。AHA 模块利用垂直方向上的 Avgpool 和水平方向上的 Maxpool 来捕捉远程依赖关系和准确的位置信息,从而有效确定不同方向上的特征退化。对比学习策略通常旨在最小化正样本之间的欧氏距离,使预测图像更接近理想图像,同时最大化负样本与预测图像之间的距离,使它们进一步远离非理想表征。

G-Howe的博客 1466

go语言开发环境的搭建-安装和配置SDK

我们在定义path变量时要注意,path变量已经有了,所以我们只需要在path变量里增加go文件夹里的bin文件夹的地址即可,具体操作如图。我们看到了一个 go.exe 的文件 其实这个文件就是用来编译go语言的代码的文件,接下来我们输入命令 go version 判断其版本 同时我们可以借此判断go安装是否成功。2.SDK是提供给开发人员使用的,其中包含了对应的开发语言的工具包(运行的工具,开发的工具,以及开发所需要的api)。GOPATH 工作目录,将来我们的go项目的工作路径。

weixin_67771119的博客 2479

右腿驱动电路设计:从共模干扰原理到生物电采集实战

在生物电信号采集领域,共模干扰是影响测量精度的核心挑战之一,其本质源于环境电磁场通过容性耦合在人体表面产生的感应电流。根据欧姆定律,由于人体组织阻抗的不均衡性,共模电流会在不同测量点产生差异化的压降,从而转化为难以滤除的差分噪声。为解决这一问题,右腿驱动技术应运而生,它通过负反馈原理主动抵消干扰,显著提升系统的共模抑制比。该技术广泛应用于心电图、脑电图等医疗电子设备中,是确保微弱生理信号质量的关键环节。本文结合工程实践,深入剖析了右腿驱动电路中的仪表放大器选型、反馈环路稳定性设计以及PCB布局布线要点,为高

weixin_31476015的博客 456

golang语言_1

Go 语言的 SDK 是什么? SDK 就是软件开发工具包。我们做 Go 开发,首先需要先安装并配置好 sdk. Golang 环境变量配置及其作用。 GOROOT: 指定 go sdk 安装目录。 Path: 指令 sdk\bin 目录:go.exe godoc.exe gofmt.exe GOPATH: 就是 golang 工作目录:我们的所有项目的源码都这个目录下。 Golang 程序的编写、编译、运行步骤是什么?能否一步执行? 编写:就是写源码 编译:go build 源码 =》 生成一个二进制的可

qq_34913864的博客 537

S-function入门及案例详解(3)——S-function进阶案例

目录1.案例描述2.案例详解3.输出波形4.对输入参数进行Mask打包 1.案例描述 设计一个蹦极系统 h为离地面高度,输入参数为长度、质量、离地面高度。 2.案例详解 步骤1.可以修改sfuntmpl函数的名称(这里修改为bengji),并在括号内增加输入参数 参数len,weight,dist分别表示长度、质量、离地面高度;长度用来初始化x0,质量用来初始化m,离地面高度用来初始化h。 function [sys,x0,str,ts,simStateCompliance] = bengji(t,x,u

Wendy的博客 1万+

大数据运营可视化:Tableau+PowerBI数据看板搭建教程

当企业数据量从“GB级”跃升到“TB级”,运营人员面临的最大挑战不再是“如何收集数据”,而是“如何让数据说话”。数据看板作为“运营指挥中心的仪表盘”,能将零散的用户行为、业务指标、流量趋势浓缩成可快速解读的视觉语言。本文结合Tableau(自由探索的“数据瑞士军刀”)与PowerBI(微软生态的“组合家具”)两大工具,从需求分析→数据准备→指标设计→视图搭建→ dashboard 组合,一步步教你搭建符合业务逻辑的运营看板。

AI智能探索者的博客 1385

Go 语言配置SDK

出现‘go‘ 不是内部或外部命令,也不是可运行的程序 或批处理文件问题的解决方案 SDK下载及安装详细过程。

m0_49589654的博客 2117

2023年12月机器人技术等级考试试卷(三级理论) 试题解析

2023年12月机器人技术等级考试试卷(三级理论) 试题解析

http://www.cierobot.com 4118

海萤物联网介绍

文章目录海萤物联网上线背景介绍地址表示方法 海萤物联网上线 本文博客链接:http://blog.csdn.net/jdh99,作者:jdh,转载请注明. 背景 物联网发展多年,通信技术众多,可分为有线和无线两大类。有线技术有基于以太网的;PLC电力线的;485,422等各种总线技术的。无线技术有基于运营商网络2G,4G的;有基于wifi,蓝牙的;有基于各个频段的无线的。在每个场景都有最适合的技术。 这些技术都有对应的协议栈,采用不同技术开发的系统会形成一个个信息孤岛,系统间很难互通。 另外物联网是同时涉及

jdh99的专栏 2万+

DeepLabv3+改进专栏

🔥【DeepLabv3+改进专栏!探索语义分割新高度】🌟 你是否在为图像分割的精度与效率发愁?📢 本专栏重磅推出:✅ 独家改进策略:融合注意力机制、轻量化设计与多尺度优化✅ 即插即用模块:ASPP+升级、解码器。

AIcurator的博客 2582

Microsoft Bitlocker企业级管理部署方案

BitLocker是Windows 10以及更高版本中内置的磁盘加密工具,是一种可靠的数据保护机制,可以保护计算机上的敏感数据不被未经授权的人访问。BitLocker的工作原理是将整个系统卷或其他数据卷加密的同时,向某个可信软件或硬件模块请求密钥解密数据。BitLocker最大的好处在于其内置于Windows系统,所以用户无需安装其他软件或购买额外的许可证或硬件设备。本文将介绍Microsoft BitLocker企业级管理部署方案,包括:BitLocker部署前的准备工作。

xueyunshengling的博客 2081

海萤物联网教程:MicroPython SDK

文章目录海萤物联网教程:MicroPython SDK简介开源安装API 海萤物联网教程:MicroPython SDK 本文博客链接:http://blog.csdn.net/jdh99,作者:jdh,转载请注明. 欢迎前往社区交流:海萤物联网社区 简介 海萤物联网的MicroPython SDK是标准Python SDK移植到MicroPython的版本,标准版本可以查看文档:海萤物联网教程:Python SDK 本文主要介绍MicroPython版本与标准版本的不同之处。 开源 github上的项目

jdh99的专栏 602

pscad IEEE标准系统搭建说明

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

海萤物联网教程:物联网RPC框架Python DCOM

文章目录海萤物联网教程:物联网RPC框架Python DCOM简介开源安装基础概念APIload:模块载入receive 接收数据register:服务注册call:同步调用请求和应答数据格式 海萤物联网教程:物联网RPC框架Python DCOM 本文博客链接:http://blog.csdn.net/jdh99,作者:jdh,转载请注明. 欢迎前往社区交流:海萤物联网社区 简介 RPC:Remote Procedure Call,远程过程调用。使用RPC可以让一台计算机的程序程调用另一台计算机的上的程序

jdh99的专栏 758

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

探索 `go-sdk`:构建高效 Go 应用的核心库

探索 go-sdk:构建高效 Go 应用的核心库 在现代软件开发领域,选择合适的工具和库对于项目的成功至关重要。今天,我们将深入探讨一个强大的 Go 语言库——go-sdk,它为开发者提供了构建各种应用程序所需的坚实基础。 项目介绍 go-sdk 是由 Blend 公司开发的核心库,旨在为 Go 开发者提供一系列可组合的包,用于构建从命令行工具到功能齐全的 Web 应用等各种软件。这个库的设计哲学...

gitblog_01038的博客 885

深度学习工具包 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下搭建Go开发环境 - 安装和配置SDK

(1) SDK 的全称(oftwareevelopmentit 软件开发工具包)(2)SDK 是提供给开发人员使用的,其中包含了对应开发语言的工具包。

where_are_you_from的博客 2347

《物联网 - 机智云开发笔记》第1章 机智云平台快速入门

机智云官网 1.1机智云与GoKit3简介 机智云为开发者提供物联网设备的自助开发工具、后台技术支持服务、设备远程操控管理、数据存储分析、第三方数据整合、硬件社交化等技术服务,也为智能硬件厂家提供一站式物联网开发和运维服务,将智能硬件产品开发周期最快缩短到半天,快速实现智能化。服务的客户主要来自消费类智能硬件厂家(智能家居、可穿戴产品),以及工业、商业应用、智慧城市建设等。 GoKit3是机智云(GizWits) 推出的物联网智能硬件开发套件(第三代),目的是帮助传统硬件快速接入互联网。 完成入网之后, 数

不问归期的博客 6343

Go语言开发环境搭建

根据Windows系统在查找可执行程序的原理,将Go所在路径定义到环境变量中,让系统帮我们去找到运行执行的程序,这样任何目录都可以执行go指令。配置的环境变量如下所示右击“我的电脑”->属性->高级系统设置->高级->环境变量->新建系统变量。该命令的运行时间更长,因为编译过程中隐藏在命令中,而上面的步骤是运行编译后的程序。其中,bin文件中的go.exe用于编译可执行文件,godoc.exe用于生产文档,dofmt.exe用于代码格式化。其中,GOPATH表示以后Go项目存放的路径,即工作目录。

2401_83649605的博客 1445

推荐开源项目:Go-SDK

推荐开源项目:Go-SDK 项目介绍 go-sdk 是一个由 Blend 公司开发的核心库,它包含了多个可组合的包,可用于构建从命令行工具到全功能Web应用的任何项目。这个库的设计理念是提供松散耦合的库,而不是一个全能的框架,这样可以让你更自由地构建和扩展你的应用程序。 项目技术分析 go-sdk 使用了 Go 语言,并要求至少使用 1.16 版本。其代码结构清晰,以可组合的包形式组织,每个包都有...

gitblog_00070的博客 416

阿里云物联网平台 Go 示例项目教程

阿里云物联网平台 Go 示例项目教程 1. 项目介绍 阿里云物联网(IoT)Go 示例项目是为开发者提供的一款快速上手的 SDK,它允许开发者使用 Go 语言轻松连接到阿里云 IoT 平台,实现设备数据的上传与下载,以及对设备的管理和控制。该项目基于阿里云官方的 IoT SDK 构建,旨在简化开发流程并提高效率。 2. 项目快速启动 安装依赖 确保您已经安装了 Go 编译器。接下来,通过 go g...

gitblog_00185的博客 585

探索百度云Go SDK:高效接入云服务的利器

探索百度云Go SDK:高效接入云服务的利器 在云计算的浪潮中,百度云以其强大的服务能力和广泛的应用场景,成为了众多开发者的首选。为了进一步简化开发者的工作流程,百度云推出了Go语言版的开发者工具包(SDK),即GO SDK。本文将深入介绍这一工具包,分析其技术特点,探讨其应用场景,并展示其独特优势。 项目介绍 百度云GO SDK是一个专为Go语言开发者设计的工具包,旨在提供一种简便的方式来接入百...

gitblog_00422的博客 615

Golang语言初识

Go 编程指南。对初学者而言,最容易错的地方拼写错误:尝试 着去看懂编译器会报告的错误信息。

mingqing的博客 788
上一篇: python版本的海萤物联网ntp服务上线
下一篇: 海萤物联网教程:物联网RPC框架MicroPython DCOM
jdh99
jdh99 领域专家: 嵌入式与硬件开发技术领域 领域专家: 嵌入式与硬件开发技术领域
博客等级 码龄18年 1468粉丝 228原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址