好多的鱼


  • Home

  • Archives

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,直接安装成功(哭笑不得脸)。

友情链接

Posted on 2019-07-12

一位前端工程师的网站 Powerless

为git生成ssh key

Posted on 2019-05-20

在命令行输入ssh-keygen –t rsa –C “johndoe@doebrothers.com“
敲三个回车之后,在用户/用户名/.ssh目录下生成两个文件,其中.pub是公钥(上传到github)

KDE 闪烁问题解决

Posted on 2019-04-17

使用KDE Plasma 5.15 ,启动器为sddm,发现在启动器界面和进入桌面过程出现闪烁。
查阅资料,有说法为intel使用开源驱动默认会导致该问题,Intel显卡的加速选项有默认方式(glamor)、加速模式(sna)和兼容模式(uxa),修改了Intel显卡的Xorg配置文件为Intel加速模式(sna),问题可解决(参照深度论坛)
在/etc/X11/xorg.conf.d/下新建20-intel.conf,内容为:

1
2
3
4
5
6
7
8
Section "Device"
Identifier "Intel Graphics"
Driver "intel"
Option "DRI" "3"
Option "AccelMethod" "sna"
#Option "PageFlip" "False"
#Option "TearFree" "True"
EndSection

打包备份后删除原有的20opengl.conf.gz
重启电脑后该问题解决

在linux下使用小度wifi

Posted on 2019-04-17

下载了一个驱动,打开看了下,是MT7601U,在内核中查找后发现内核已经自带该驱动。
mask MT7601U (drivers) to M ,
build kernel
enjoy~

安装Gentoo环境

Posted on 2019-04-11

安装系统过程

  1. 打开官网(https://wiki.gentoo.org/)
  2. 下载stage3(可以在http://mirrors.163.com/gentoo/releases/x86/autobuilds/current-stage3-i686/地址下载)
  3. 下载光盘,做成U盘启动(如果烧不进去,使用UltraISO,使用RAW格式烧写就可以了)
  4. 挂载一堆东西
  5. xz stage3xxxx.tar.xz
  6. tar xvf stage3xxxx.tar
  7. chroot
  8. sources /etc/profile
  9. emerge-webrsync
  10. eselect profile list
  11. eselect profile set
  12. 编辑/etc/portage/make.conf
  13. emerge –ask –verbose –update –deep –newuse @world
  14. emerge –ask sys-kernel/gentoo-sources
  15. cd /usr/src/linux
  16. 配置内核,注意:
    1. 如果内存超过4G ,要配置PAE选项
    2. 如果用手机上网,配置NIDIS选项 包括USBNET
    3. 如果用UEFI直接启动,注意相关选项
  17. make && make modules_install
  18. make install
  19. 安装引导程序
    1. emerge –ask –verbose sys-boot/grub:2
    2. grub-install /dev/sda
    3. grub-mkconfig -o /boot/grub/grub.cfg
  20. emerge dhcpcd
  21. emerge usbutils pciutils
  22. passwd设置一下root密码
  23. 将/etc/config.d/hwclock 中的时间从UTC改为Local,防止修改时钟
  24. 重启,增加新用户

注意:

  1. 该阶段出现莫名死机,后发现是系统光盘不支持PAE,因此只能利用大约2.3G左右内存。由于内存过小,在编译GCC时死机或者link失败,解决方法:创建一个虚拟内存文件,然后用作swap
    • dd if=/dev/zero of=/home/swap/swapfile bs=1024 count=512K (创建2G的虚拟内存,实际用了不到1G)
    • mkswap ./swapfile
    • swapon ./swapfile
  2. 查看磁盘ID,使用blkid
  3. 查阅内核状态,看/proc/config.gz,用zcat config.gz直接看
  4. 编译时候查阅硬件温度,可以用sensors(用emerge lm_sensors安装)
  5. 如果需要有sudo权限,需要emerge sudo,然后在etc目录下修改sudoers,用户名(@用户组) 可执行的范围(用逗号隔开),典型为 user_one ALL=(ALL) /usr/bin/vi,bin/chown,/usr/bin/emerge

配置桌面环境

我选择了KDE5 (Plasma ),因为很漂亮而且使用便利,插件多
注意,要在前面第11步选择合适的profile

  1. emerge xorg-server
  2. env-update && source /etc/profile
  3. startx看一眼
  4. 如果成功: emerge –ask plasma-meta(超长时间,大约190个包左右)
  5. emerge xdm
  6. emerge sddm
  7. rc-update add xdm default

待解决问题

  1. 不能图形界面关机
    解决方式:安装dbus驱动,并通过rc-update add default加入到启动中,保证在sddm之前启动(2019-04-14)
  2. 桌面应用过少
  3. 本地化问题
前一页1…345下一页

41 posts
16 tags
© 2026 qinsibo
Powered by Hexo
|
Theme — NexT.Gemini v5.1.4
津ICP备19000975号-1
# 津ICP备19000975号-1