好多的鱼


  • Home

  • Archives

Three.js 示例

Posted on 2023-10-25

Three.js 示例

将python打包为exe

Posted on 2023-10-25

最近和结构的同事一起玩three.js,做了一个简易的展示,先启动一个python的http server,然后通过浏览器访问httpserver来呈现3D图像。在操作中,发现同事对命令行启动python非常不习惯,于是将python的.py文件打包为exe,只要放在文件夹下,双击即可执行。
python服务器代码用AI生成如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import http.server
import socketserver
from http.server import SimpleHTTPRequestHandler
import threading
import webbrowser
import time

PORT = 8000

class CORSRequestHandler (SimpleHTTPRequestHandler):
def end_headers (self):
self.send_header('Access-Control-Allow-Origin', '*')
SimpleHTTPRequestHandler.end_headers(self)

Handler = CORSRequestHandler

def open_browser():
time.sleep(3)
print("Opening default browser: ", webbrowser.get().name)
webbrowser.open("http://127.0.0.1:8000/")

with socketserver.TCPServer(("", PORT), Handler) as httpd:
print("serving at port", PORT)
threading.Thread(target=open_browser).start()
httpd.serve_forever()

启动命令行,进入目录,执行打包软件安装:
pip install -i https://pypi.python.org/simple pyinstaller

最开始用华为云的源,没有这个包,指定了原始源,自动安装一些关联包后返回成功。

然后在目录下:
pyinstaller –onefile httpserver.py
该程序会自动打包python和相关依赖到文件中,注意,这个依赖只管python的,如果有数据或者图片,需要额外添加
打完包后,在dist目录会有一个exe文件,需要用的时候,拷贝到指定目录,双击就可以直接执行了。

昇腾A2板卡调测

Posted on 2023-08-09

待做清单:
-[ ] 调用opencv接口
-[x] 调用Python 的opencv接口
-[ ] 调用Cpp的opencv接口
-[ ] 部署pytorch服务
-[x] 本地文件能够AI处理
-[ ] 能够编写网络处理图像定位
-[ ] 能够进行图像分割
-[ ] 能够进行图像比对
-[ ] 能够进行轨迹预测和评估
-[ ] 找一个运动跟踪模型跑跑试试
-[ ] 跑real-Time-Voice-Cloning声音克隆
-[ ] 跑openAi的Whisper模型试试中文

华为平台

-[x] 在modelArts上部署服务
-[ ] 昇腾平台上跑车牌识别
-[ ] 跑一下昇腾平台的sd模型
-[ ] 跑一下昇腾的语音识别
-[ ] 做一个资源监控软件
-[x] 打通A2网卡
-[x] 打通A2硬盘

新增问题:
打通网卡的内核无法使用USB设备?

fastChat测试

Posted on 2023-07-09

创建fastChat过程:

创建conda环境
conda create -n fastchat38 python=3.8
conda activate fastchat38

安装支持cuda 的pytorch
pip3 install torch torchvision torchaudio -index-url https://download.pytorch.org/whl/cu118

连不上,改用conda安装
conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia

pip3 install fschat
git clone https://github.com/lm-sys/Fastchat.git

mkdir -p models/vicuna-7b-v1.3
下载模型到该目录,源
地址:https://huggingface.co/lmsys/vicuna-7b-v1.3

补充环境
pip install mess_ratio

python -m fastchat.serve.cli –model-path models/vicuna-7b-v1.3
可以通过参数切换CPU和GPU。我用CPU 志强4210和GPU4090分别测试,差异还是很明显的,GPU跑在100w左右,输出时间只有CPU的四分之一或者更短。

跑web(尚未跑通):

conda activate fastchat38
cd D:\tmp\FastChat\Fastchat

python -m fastchat.serve.controller
python -m fastchat.serve.model_worker –model-path models/vicuna-7b-v1.3

python -m fastchat.serve.test_message –model-name vicuna-7b-v1.3
python -m fastchat.serve.gradio_web_server

· 启动控制器
python3 -m fastchat.serve.controller
· 启动model worker
python3 -m fastchat.serve.model_worker –model-path /path/to/vicuna/weights
当进程完成模型的加载后,会看到「Uvicorn running on …」。
· 发送测试消息
python3 -m fastchat.serve.test_message –model-name vicuna-13b
· 启动gradio网络服务器
python3 -m fastchat.serve.gradio_web_server

在图形中展示

Posted on 2022-02-09

参考资料依旧为《人工智能原理与实践-基于python语言和tensorFlow》
使用 TensorBoard

安装方式为:在conda终端中输入:
conda install tensorboard
然后,生成图
writer = tf.summary.FileWriter('.\my_graph',sess.graph)
退出后再终端输入
tensorboard --logdir="my_graph"

tf样例1和tf样例2

Posted on 2022-02-06

首先测试了一个书上样例:

1
2
3
4
5
6
7
8
9
10
import tensorflow as tf
a = tf.constant(5,name="input_a")
b = tf.constant(3,name="input_b")
c = tf.multiply(a,b,name="mul_c")
d = tf.add(a,b,name="add_d")
e = tf.add(c,d,name="add_e")

sess = tf.Session()
sess.run(e)

报错:

1
2
3
4
  File "C:\Users\qinsi\tensorflow_workspace\steam_tf.py", line 8, in <module>
sess = tf.Session()
AttributeError: module 'tensorflow' has no attribute 'Session'

这个在昨天的样例中碰到过,是v1和v2的版本区别。
修改为
sess = tf.compat.v1.Session()
后可以跑起来,在run步骤报如下错误:
Tensor.graph is meaningless when eager execution is enabled.
先找了一个hello跑了一下,可用:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @File : TensorFlow入门操作.py
# @Author: 赵路仓
# @Date : 2020/3/26
# @Desc :
# @Contact : 398333404@qq.com

import tensorflow as tf
import os
os.environ["CUDA_VISIBLE_DEVICES"]="0"

tf.compat.v1.disable_eager_execution()
hello=tf.constant('---Hello,TensorFlow')
config=tf.compat.v1.ConfigProto()
config.gpu_options.per_process_gpu_memory_fraction = 0.9
sess=tf.compat.v1.Session(config=config)
print(sess.run(hello))

然后查阅资料修改文件,找到一个比较通用的方法,在前面添加如下语句:

1
2
3
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

整个程序如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @File : TensorFlow入门操作2.py
# @Author: qinsibo.com
# @Date : 2022/02/06
# @Desc :
# @Contact : qinsibo@sohu.com
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

a = tf.constant(5,name="input_a")
b = tf.constant(3,name="input_b")
c = tf.multiply(a,b,name="mul_c")
d = tf.add(a,b,name="add_d")
e = tf.add(c,d,name="add_e")
# 关闭动态图机制
tf.compat.v1.disable_eager_execution()
#
tf.compat.v1.get_default_graph()
sess = tf.compat.v1.Session()
hello=tf.constant('---Hello,TensorFlow')
#print(sess.run(hello))
print(sess.run(e))
sess.close()

输入结果为:

1
2
3
4
5
6
7
8
9
(TensorFlowGPU3_9) C:\Users\qinsi\tensorflow_workspace>python steam_tf.py
WARNING:tensorflow:From C:\Users\qinsi\anaconda3\envs\TensorFlowGPU3_9\lib\site-packages\tensorflow\python\compat\v2_compat.py:107: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version.
Instructions for updating:
non-resource variables are not supported in the long term
2022-02-06 13:10:41.291245: I tensorflow/core/platform/cpu_feature_guard.cc:151] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2022-02-06 13:10:41.798922: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1525] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 1360 MB memory: -> device: 0, name: NVIDIA GeForce GTX 750 Ti, pci bus id: 0000:01:00.0, compute capability: 5.0
23

结果正确
手里的资料还是有点老,后续争取找一下tf2的相关资料进行进一步学习。

安装tensorFlow

Posted on 2022-02-05

步骤:
1.下载anaconda虚拟环境,默认安装
2.下载CUDA-tools,默认安装 。测试是否成功方法,打开命令行,输入nvcc -V 看到类似如下版本号等信息就是成功

1
2
3
4
5
6
7
(TensorFlowGPU3_9) C:\Users\qinsi>nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Fri_Dec_17_18:28:54_Pacific_Standard_Time_2021
Cuda compilation tools, release 11.6, V11.6.55
Build cuda_11.6.r11.6/compiler.30794723_0

3.在anaconda中选择environments 选择中间最下面的create,创建默认环境TensorFlowGPU3_9
4.点三角号启动,选择Open Terminal
5.输入pip install tensorflow-gpu
注意:如报错,可尝试先安装pip install pip-search

6.安装完成后,python执行,然后

import tensorflow as tf
hello = tf.constant(‘hello,tf’)
sess = tf.compat.v1.Session()

输出显卡信息:
2022-02-06 02:32:19.969053: I tensorflow/core/platform/cpu_feature_guard.cc:151] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2022-02-06 02:32:20.583606: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1525] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 1360 MB memory: -> device: 0, name: NVIDIA GeForce GTX 750 Ti, pci bus id: 0000:01:00.0, compute capability: 5.0
表示安装成功。

Atlas 平台测试

Posted on 2022-02-03

使用Atlas平台进行调试
参照华为 陈老师的相关教程
陈老师的gitee地址:
https://gitee.com/shiner-chen
手头设备平台为:
DLAP221

计划为
1.按照陈老师的样子搭建vscode调试环境
2.以图片修改例子为基础,确认开发流程

Gentoo无法挂载磁盘问题

Posted on 2019-08-27

在linux环境下挂载windows分区失败,dmesg提示
ntfs: (device sda9): parse_options(): Unrecognized mount option windows_names.
安装ntfs工具解决。

在U盘上安装linux开发环境

Posted on 2019-08-27

单位有个项目用arm9,使用一个老版本的交叉编译GCC,原有开发环境构建于32位linux。

最近该项目开始二开,领到新电脑的员工发现只能使用uefi引导,导致原指定操作系统无法使用,体现为安装后无法启动系统。

经过分析和查阅,认为是该32位系统无法支持uefi,鉴于后续64位系统将成为主流,有必要将开发环境迁移到64位系统上。初步考虑mint 19.4,安装后无法启动,提示init文件错误,查阅认为efi问题。gentoo尝试成功,但配置过程复杂且不适合作为公司开发环境。选择轻量级lubuntu,发现制作的u盘可以被正确识别和启动,但是同样存在安装到硬盘后无法启动系统的情况,于是考虑通过u盘做过渡,使用本地硬盘+u盘启动的方式,考虑u盘主要用于引导,其中内核部分放在内存,而基本工具可以使用硬盘分区,速度影响应该可接受。

首先修改u盘根目录下/boot/下grub.cfg的参数,删除quiet和splash(便于观察启动信息),删除boot=casper(该选项是通知内核使用liveCD方式启动,最后会导致系统以CDROM方式挂载。

为了能够具有一定的通用性,使用UUID指定启动盘,root=UUID=(号码),UUID通过blkid 获得 blkid /dev/sdc2

测试U盘内核似乎有一些问题,使用安装后的boot分区的内核和image替代。

启动后发现启动项,选择后,可正确引导进入linux桌面,根分区可读写。

后续花絮:

在安装环境中发现lubuntu各种缺东西,一怒之下换成了kubunut,直接安装成功(哭笑不得脸)。

<i class="fa fa-angle-left"></i>1234<i class="fa fa-angle-right"></i>

36 posts
13 tags
© 2025 John Doe
Powered by Hexo
|
Theme — NexT.Gemini v5.1.4
津ICP备19000975号-1
# 津ICP备19000975号-1