Node-RED 是一个流程编程工具,可以用来连接各种硬件或API,使其可视化,简化和自动化。Node-RED 同时支持 JavaScript 和类似 HTML 的语言流程,可以方便地搭建流程逻辑并实现数据交互。而 npm 包 node-red-contrib-redtensor 的出现,也使数据处理更加高效化。
简介
node-red-contrib-redtensor 是一款基于 TensorFlow.js 的 Node-RED 库,提供了对深度学习工具的支持,使在 Node-RED 中处理大规模的深度学习数据变得更加方便快捷。它是一个强大的工具,能够支持大部分深度学习的任务,包括图像分类、文字分析、预测分析和自然语言处理等。
安装
使用 npm,我们可以轻松地安装 node-red-contrib-redtensor:
npm install node-red-contrib-redtensor
使用
导入数据
node-red-contrib-redtensor 提供了方便的标签和工具,可以使您方便地导入数据。例如,您可以使用图像的 URL 或磁盘上的本地文件,将数据导入此工具中。下面是一个示例,演示如何使用 node-red-contrib-redtensor 从 URL 导入图像数据:
[{"id":"6e20296a.c93b6c","type":"image loader","z":"35f6ca78.b6c656","name":"Import image data using URL","url":"https://www.tensorflow.org/images/iris_three_species.jpg","output":"buffer","x":440,"y":360,"wires":[["1cf48bf8.d327ad"]]},{"id":"1cf48bf8.d327ad","type":"image processing","z":"35f6ca78.b6c656","name":"Image processing with redtensor","imageconfig":"{\"width\":100,\"height\":100,\"mode\":\"crop\"}","filters":"[\"pixelate\"]","image":"buffer","x":690,"y":360,"wires":[["9453505b.aba5d"]]},{"id":"9453505b.aba5d","type":"image output","z":"35f6ca78.b6c656","name":"Display the image","to":"browser","imageinput":"image","x":980,"y":360,"wires":[]}]
上述示例演示了如何从 URL 导入图像数据,并使用 redtensor 进行像素化处理的过程。
使用数据
node-red-contrib-redtensor 也为您提供了各种不同类型的节点,都具有各自的用途和能力,例如 Graph 节点用于生成图表,CSV 合并节点用于将多个 CSV 文件合并在一起等。使用这些节点,您可以方便地对 TensorFlow.js 进行操作和研究,产生更高效和精确的深度学习模型。
[{"id":"4ca5dba5.5c66fc","type":"tab","label":"Simple ML Example","disabled":false,"info":""},{"id":"be6f3f6b.3f8688","type":"inject","z":"4ca5dba5.5c66fc","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":120,"wires":[["6885f5b0.5d5e5c"]]},{"id":"838821f6.1fcd38","type":"debug","z":"4ca5dba5.5c66fc","name":"Result of prediction","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":590,"y":220,"wires":[]},{"id":"51ec94f5.93a49c","type":"http request","z":"4ca5dba5.5c66fc","name":"Download dataset","method":"GET","ret":"bin","url":"https://storage.googleapis.com/tfjs-examples/multivariate-linear-regression/data/boston-housing-train.csv","tls":"","x":180,"y":380,"wires":[["b9ed38d.7ee094"]]},{"id":"b9ed38d.7ee094","type":"csv parse","z":"4ca5dba5.5c66fc","name":"","sep":",","hdrin":true,"hdrout":"none","multi":"one","ret":"obj","temp":"","skip":"0","x":310,"y":460,"wires":[["d1a78dc1.58f4d8"]]},{"id":"d1a78dc1.58f4d8","type":"tensor","z":"4ca5dba5.5c66fc","name":"Training data","model":"https://storage.googleapis.com/tfjs-examples/multivariate-linear-regression/dist/index_bundle.js","x":520,"y":460,"wires":[["86782a44.639358"]]},{"id":"86782a44.639358","type":"linear-regression","z":"4ca5dba5.5c66fc","name":"Linear Regression ML model","input_shape":"","layers":[{"input_shape":"13"}],"learning_rate":"0.01","batch_size":"10","epochs":"1000","trainable":true,"tensor":"none","x":780,"y":460,"wires":[["838821f6.1fcd38"]]},{"id":"6885f5b0.5d5e5c","type":"http request","z":"4ca5dba5.5c66fc","name":"Download dataset","method":"GET","ret":"bin","url":"https://storage.googleapis.com/learnjs-data/model/handpose/manifest.json","tls":"","x":180,"y":260,"wires":[["cc9d81e3.3fd0e8"]]},{"id":"cc9d81e3.3fd0e8","type":"json","z":"4ca5dba5.5c66fc","name":"","property":"payload","action":"","pretty":false,"x":320,"y":320,"wires":[["361d786.31ada58"]]},{"id":"361d786.31ada58","type":"handpose-model","z":"4ca5dba5.5c66fc","name":"","model":"payload","modelinput":"","x":520,"y":320,"wires":[["a099f090.a8ee"]]},{"id":"a099f090.a8ee","type":"webcam","z":"4ca5dba5.5c66fc","name":"","device":"0","location":"","resolution":"640x480","flip":"no","x":690,"y":320,"wires":[["a1f48d77.c4c448"]]},{"id":"a1f48d77.c4c448","type":"handpose-sample","z":"4ca5dba5.5c66fc","name":"","downsample":"4","upsample":"0","smooth":"3","scorethreshold":"0.7","maxnumhands":"1","showoutput":"yes","x":890,"y":320,"wires":[[]]}]
上述示例演示了一个使用 Linear Regression 模型进行简单的机器学习任务的例子。我们将从 URL 下载一个数据集,预测内部数据集的房价,然后将结果输出到 Debug 节点。
结论
通过以上的介绍,我们可以看到,node-red-contrib-redtensor 为 Node-RED 提供了更加方便快捷的数据处理和深度学习模型的实现。它能够大大减少编码时间和难度,提高生产力和产出质量。我们相信,在 Node-RED 的旅程中应该会有越来越多的人选择使用 node-red-contrib-redtensor。
来源:JavaScript中文网 ,转载请注明来源 https://www.javascriptcn.com/post/60066b5251ab1864dac668fb