Jammy@Jetson Orin - Tensorflow Keras Get Started: 000 setup for tutorial

embedded/2024/9/24 5:19:40/

Jammy@Jetson Orin - Tensorflow & Keras Get Started: 000 setup for tutorial

  • 1. 源由
  • 2. 搭建环境
    • 2.1 安装IDE环境
    • 2.2 安装numpy
    • 2.3 安装keras
    • 2.4 安装JAX
    • 2.5 安装tensorflow
    • 2.6 安装PyTorch
    • 2.7 安装nbdiff
  • 3. 测试DEMO
    • 3.1 numpy版本兼容问题
    • 3.2 karas API - model.compile问题
    • 3.3 karas API - model.predict问题
  • 4. 总结
  • 5. 参考资料

1. 源由

凡事开头难!入门搭建环境难!

这里就从最基本的环境搭建和大家共一起勉!

2. 搭建环境

2.1 安装IDE环境

  • jupyterlab环境
$ pip install jupyterlab
$ jupyter lab
  • jupyternotebook环境
$ pip install notebook
$ jupyter notebook

注:推荐使用jupyterlab。

2.2 安装numpy

$ pip install -U numpy  //升级到最新版本$ python
Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> numpy.__version__
'1.26.4'
>>>

注:升级到指定版本可以使用命令pip install numpy==1.24.3

keras_46">2.3 安装keras

$ pip install --upgrade keras$ python
Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import keras
>>> keras.__version__
'3.3.2'
>>>

2.4 安装JAX

  • CPU-only (Linux/macOS/Windows)
$ pip install -U "jax[cpu]"
  • GPU (NVIDIA, CUDA 12, x86_64)
$ pip install -U "jax[cuda12_pip]" -f https://storage.googleapis.com/jax-releases/jax_cuda_releases.html

注:更多关于JAX的硬件版本信息,详见:Installing JAX

tensorflow_77">2.5 安装tensorflow

$ pip install tensorflow$ python
Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> tf.__version__
'2.16.1'
>>> tf.__path__
['/home/daniel/.local/lib/python3.10/site-packages/keras/api/_v2', '/home/daniel/.local/lib/python3.10/site-packages/keras/_tf_keras', '/home/daniel/.local/lib/python3.10/site-packages/tensorflow', '/home/daniel/.local/lib/python3.10/site-packages/tensorflow/_api/v2']
>>>

2.6 安装PyTorch

具体安装版本因硬件差异,命令不同,详见:Install pytorch

在这里插入图片描述因为,笔者这里环境是Jetson Orin,所以选择了上面的配置版本:

$ pip install torch torchvision torchaudio

2.7 安装nbdiff

鉴于.ipynb文件会包含最后一次执行的输出信息,不像通常代码diff那样可以看的很清楚,这里需要安装一个类似diff的命令。

$ pip install nbdime$ nbdiff --help
usage: nbdiff [-h] [--version] [--config] [--log-level {DEBUG,INFO,WARN,ERROR,CRITICAL}] [-s] [-o] [-a] [-m] [-i] [-d] [--color-words] [--no-color] [--no-git] [--no-use-diff] [--out OUT][base] [remote] [paths ...]Compute the difference between two Jupyter notebooks.positional arguments:base                  the base notebook filename OR base git-revision.remote                the remote modified notebook filename OR remote git-revision.paths                 filter diffs for git-revisions based on pathoptions:-h, --help            show this help message and exit--version             show program's version number and exit--config              list the valid config keys and their current effective values--log-level {DEBUG,INFO,WARN,ERROR,CRITICAL}set the log level by name.--color-words         whether to pass the --color-words flag to any internal calls to git diff--no-color            prevent use of ANSI color code escapes for text output--no-git              prevent use of git for formatting diff/merge text output--no-use-diff         prevent use of diff/diff3 for formatting diff/merge text output--out OUT             if supplied, the diff is written to this file. Otherwise it is printed to the terminal.ignorables:Set which parts of the notebook (not) to process.-s, --sources, -S, --ignore-sourcesprocess/ignore sources.-o, --outputs, -O, --ignore-outputsprocess/ignore outputs.-a, --attachments, -A, --ignore-attachmentsprocess/ignore attachments.-m, --metadata, -M, --ignore-metadataprocess/ignore metadata.-i, --id, -I, --ignore-idprocess/ignore identifiers.-d, --details, -D, --ignore-detailsprocess/ignore details not covered by other options.

3. 测试DEMO

学习是一个过程,是一种大学生应该掌握的技能。手把手教那是在学校,真正的学习是不断的自我学习和提高,这种螺旋式学习技能将会受益一辈子!

即使很好的搭建了环境,代码依然会出现问题!

001_Keras-Linear-Regression

$ git log -n 2
commit 84b7f5ee7c80d9faecf79af96f8a677f47c44f0d (HEAD -> main, origin/main, origin/HEAD)
Author: Daniel Li <lida_mail@163.com>
Date:   Tue Apr 23 16:49:42 2024 +0800Fix Keras-Linear-Regression demo code issue with Jammy(Jetson Orin)commit 8c89b4c2b9e9df2e854f280ce19ed3010c7ac2fc
Author: Daniel Li <lida_mail@163.com>
Date:   Tue Apr 23 15:00:46 2024 +0800Add raw 001_Keras-Linear-Regression/Keras-Linear-Regression.ipynb

3.1 numpy版本兼容问题

在这里插入图片描述
解决方法:numpy版本降级

$ pip install numpy==1.23.4

3.2 karas API - model.compile问题

在这里插入图片描述

解决方法:修正API入参参数

## modified /cells/15/source:
@@ -1,2 +1,2 @@
-model.compile(optimizer=tf.keras.optimizers.RMSprop(lr=.005),
+model.compile(optimizer=tf.keras.optimizers.RMSprop(learning_rate=.005),loss='mse')

3.3 karas API - model.predict问题

在这里插入图片描述
解决方法:修正API入参参数

## modified /cells/23/source:
@@ -1,5 +1,5 @@# Predict the median price of a home with [3, 4, 5, 6, 7] rooms.
-x = [3, 4, 5, 6, 7]
-y_pred = model.predict(x)
-for idx in range(len(x)):
-    print("Predicted price of a home with {} rooms: ${}K".format(x[idx], int(y_pred[idx]*10)/10))+rooms = [3, 4, 5, 6, 7]
+y_pred = model.predict(x = np.array(rooms))
+for idx in range(len(rooms)):
+    print("Predicted price of a home with {} rooms: ${}K".format(rooms[idx], int(y_pred[idx][0]*10)/10))

4. 总结

学习的第一步,总是感觉那么繁琐,如果感兴趣可以直接写一个setup.sh脚本。

但从学习的角度,一个问题,一个脚印,一步步的操作,纠错,理解,为后续组件/系统的理解可以奠定非常好的基础。

万事开头难,其实就是这么简单的一回事情!

关于线性拟合,这个大家估计能看到这里的兄弟们,都懂的。后面我们也会专门看下科学计算方法和这个神经网络拟合之间的差异。

切记一点,神经网络这个是模拟人类大脑的的工作模式,尽管对于人类大脑工作原理远没有搞得这么清楚,但是从目前的一些视频/图片识别角度看,该方法确实比较好的解决了多因素预测的准确性问题(大概率的准确性)。

相信数学原理更深层次的论证有待去研究渐近和收敛的问题,或者说需要更好的专业领域知识叠加神经网络算法来做到更好的应用。

5. 参考资料

【1】Jammy@Jetson Orin - Tensorflow & Keras Get Started


http://www.ppmy.cn/embedded/12129.html

相关文章

在docker容器中编译 rk3588 ubuntu固件

文件准备 Linux SDK ---- rk3588_linux_release_20230114_v1.0.6c_0*Ubuntu根文件系统 ---- Ubuntu22.04-Xfce_RK3588_v3.11-27_20240410.img.7z 硬件环境 一个可联网的linux机器&#xff0c;并且装有docker 打包一个docker编译环境 Dockerfile内容 直接通过dockerfile构…

OpenHarmony开源鸿蒙NEXT星河版内核嵌入式编程

一、前景提要 2024年1月18日&#xff0c;华为放出HarmonyOS NEXT 鸿蒙星河版开发者预览版本&#xff08;不是HarmonyOS NEXT版&#xff0c;是HarmonyOS NEXT星河版&#xff09;&#xff0c;首次提到用鸿蒙内核&#xff08;暂命名&#xff09;取代了Linux内核。 该内核源码还未放…

项目实践---贪吃蛇小游戏(下)

对于贪吃蛇小游戏&#xff0c;最主要的还是主函数部分&#xff0c;这里就和大家一一列举出来&#xff0c;上一章已经写过头文件了&#xff0c;这里就不多介绍了。 首先就是打印桌面&#xff0c;也就是背景&#xff0c;则对应的代码为&#xff1a; void SetPos(short x, short …

构建NodeJS库--前端项目的打包发布

1. 前言 学习如何打包发布前端项目&#xff0c;需要学习以下相关知识&#xff1a; package.json 如何初始化配置&#xff0c;以及学习npm配置项&#xff1b; 模块类型type配置&#xff0c; 这是nodejs的package.json的配置main 入口文件的配置 webpack 是一个用于现代 JavaSc…

电子信息制造工厂5G智能制造数字孪生可视化平台,推进数字化转型

电子信息制造工厂5G智能制造数字孪生可视化平台&#xff0c;推进数字化转型。5G智能制造数字孪生可视化平台利用5G网络的高速、低延迟特性&#xff0c;结合数字孪生技术和可视化界面&#xff0c;为电子信息制造工厂提供了一种全新的生产管理模式。不仅提升生产效率&#xff0c;…

程序猿成长之路之数据挖掘篇——朴素贝叶斯

朴素贝叶斯是数据挖掘分类的基础&#xff0c;本篇文章将介绍一下朴素贝叶斯算法 情景再现 以挑选西瓜为例&#xff0c;西瓜的色泽、瓜蒂、敲响声音、触感、脐部等特征都会影响到西瓜的好坏。那么我们怎么样可以挑选出一个好的西瓜呢&#xff1f; 分析过程 既然挑选西瓜有多个…

酷开科技逐步为用户构建健全的智慧家庭生活场景

大规模与精细化人群技术则是通过大量的计算能力和精细化的运营能力&#xff0c;建立用户专属数据储存区域&#xff0c;使得用户在使用不同电视的观影偏好和兴趣能够能够得以延续。 不拘泥于自有品牌终端数量&#xff0c;酷开系统除了集成在创维电视上&#xff0c;还服务于飞利…

gitlab关联新仓库

如果你想要将现有的Git仓库提交&#xff08;或推送&#xff09;到一个新的远程地址&#xff0c;你可以通过以下步骤来完成&#xff1a; 查看现有的远程仓库&#xff1a; 首先&#xff0c;确认你当前的仓库有哪些远程地址。 git remote -v如果输出中显示了旧的远程地址&#x…