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

ops/2024/9/24 14:23:54/

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/ops/17427.html

相关文章

2023-2024年度广东省职业院校学生技能大赛“ 网络系统管理”赛项竞赛规程(正式稿)

2023-2024年度广东省职业院校学生技能大赛“ 网络系统管理”赛项竞赛规程&#xff08;正式稿&#xff09; 信息安全管理与评估 网络系统管理 网络搭建与应用 云计算 软件测试 移动应用开发 任务书&#xff0c;赛题&#xff0c;解析等资料&#xff0c;知识点培训服务 添加博主wx…

2024.4.28 机器学习周报

目录 引言 Abstract 文献阅读 1、题目 2、引言 3、创新点 4、总体流程 5、网络结构 5.1、损失函数 5.2、Confidence Maps 5.3、Part Affinity Fields(PAFs) 5.4、多人的PAFs 6、实验 7、结论 深度学习 yolov8实现目标检测和人体姿态估计 Yolov8网络结构 yaml…

从零入门区块链和比特币(第二期)

欢迎来到我的区块链与比特币入门指南&#xff01;如果你对区块链和比特币感兴趣&#xff0c;但不知道从何开始&#xff0c;那么你来对地方了。本博客将为你提供一个简明扼要的介绍&#xff0c;帮助你了解这个领域的基础知识&#xff0c;并引导你进一步探索这个激动人心的领域。…

C# 图像处理 添加水印

方法1&#xff0c;使用自带的画刷进行绘制水印 示例代码 public partial class Form1 : Form{public Form1(){InitializeComponent();}string photoPathstring.Empty;Bitmap image null;private void button1_Click(object sender, EventArgs e) //选择照片{OpenFileDialog d…

前端入门:HTML(列表和边框案例)

1.列表知识&#xff1a; list-style-position有两个值&#xff0c;分别是inside&#xff0c;outside&#xff0c;分别表示在标签里面和在标签外面。 2.案例&#xff1a; 源代码&#xff1a; html: <body> <div class"bigBox"> <div>在线解答问题…

反映工业发展质量与效益的主要指标有哪些

我国经济已由高速增长阶段转向高质量发展阶段&#xff0c;这是新时代我国经济发展的基本特征。推动高质量发展&#xff0c;是保持经济持续健康发展的必然要求&#xff0c;是适应我国社会主要矛盾变化和全面建成小康社会、全面建设社会主义现代化国家的必然要求&#xff0c;是遵…

掩码讲解,以及生成

掩码生成模块的原理主要基于特定的算法和规则&#xff0c;用于生成一个掩码矩阵&#xff0c;该矩阵与输入序列的长度相同&#xff0c;由0和1组成。这个掩码矩阵的作用是控制模型在处理序列数据时忽略无效部分。 在自注意力机制中&#xff0c;掩码被用来屏蔽无效的位置&#xff…

YOLOV5 TensorRT部署 BatchedNMS(engine模型推理)(下)

主要是在王新宇代码的基础上改进,引入对BatchedNMS的解码 文章目录 1. 修改yolov5.cpp2.修改yololayer.h1. 修改yolov5.cpp 首先增加全局变量,名字根据转onnx时修改的节点名字来,查看onnx文件可以看到,顺序不要弄错。 const char *INPUT_NAME = “images”; const char …