小行星

热爱平淡,向往未知


  • 首页

  • 分类

  • 归档

  • 关于

  • 阅读排行

  • 搜索

tensorflow学习

发表于 2018-08-Tue | 阅读次数:

两步法

  1. 定义计算
  2. 执行计算

计算图

  1. node: operations/variable
  2. edge: tensors

hello world code

1
2
3
4
5
import tensorflow as tf
a = tf.add(3, 5)
sess = tf.Session()
print(sess.run(a))
sess.close()
1
2
3
4
5
6
7
8
9
10
11
# Creates a graph.
with tf.device('/gpu:2'):
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], name='b')
c = tf.multiply(a, b)

# Creates a session with log_device_placement set to True.
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))

# Runs the op.
print(sess.run(c))
1
2
3
4
5
6
7
8
g1 = tf.get_default_graph()
g2 = tf.Graph()
# add ops to the default graph
with g1.as_default():
a = tf.Constant(3)
# add ops to the user created graph
with g2.as_default():
b = tf.Constant(5)

python 调试输出变量

发表于 2018-08-Mon | 阅读次数:
1
2
fout = open("out.txt", "w+")
fout.write(repr(arr[0]))

tmux 查找pid所在session

发表于 2018-08-Mon | 分类于 长文 | 阅读次数:

先找到

1
tmux list-panes -a -F "#{pane_pid} #{pane_id}" | grep ^PID

但是发现无法找到,查阅man手册发现pane_pid PID of first process in pane

所以找到tty编号pts/159

1
2
ps aux |  grep 12934 | grep -v grep
me 12934 1.5 0.1 23917648 80292 pts/159 Sl+ Aug19 15:00 python train.py

然后找对应session name

1
2
tmux list-panes -a -F "#{pane_pid} #{pane_tty} sname:#{session_name} widx:#{window_index} pidx:#{pane_index}"  |  grep pts/159
31425 /dev/pts/159 sname:49 widx:3 pidx:1

https://man.cx/tmux

pytorch 直接申请gpu空间

发表于 2018-08-Sun | 阅读次数:
1
mat = torch.zeros((51, 48), dtype=torch.float, device=device)

pytorch 自带mse loss计算慢

发表于 2018-08-Sun | 阅读次数:

测试发现自带的调用一次需要0.1s………

自带的mse loss计算慢,自定义一个

1
2
3
4
def self_mseloss(y_input, y_target):
num = torch.numel(y_input)
mse_loss = torch.sum((y_input - y_target) ** 2)
return mse_loss / num

pytorch 自定义parameter

发表于 2018-08-Sun | 阅读次数:
1
torch.nn.Parameter()

sqrt 0的位置没有导数

发表于 2018-08-Sat | 分类于 长文 | 阅读次数:

满屏的NaN gradient, 最后发现是因为sqrt 0的位置是没有导数的,写代码还需时刻查看是否可导

pip查看包版本

发表于 2018-08-Sat | 阅读次数:
1
2
$ pip freeze | grep lxml
lxml==2.3

pip install 忽略错误

发表于 2018-08-Sat | 阅读次数:
1
cat requirements.txt | xargs -n 1 pip install

https://stackoverflow.com/questions/22250483/stop-pip-from-failing-on-single-package-when-installing-with-requirements-txt

pip加速

发表于 2018-08-Sat | 阅读次数:

~/.pip/pip.conf

1
2
3
4
5
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/

[install]
trusted-host=mirrors.aliyun.com

1…192021…59
fangyh

fangyh

最爱的是那苍穹之外的浩渺宇宙

588 日志
4 分类
66 标签
© 2020 fangyh
由 Hexo 强力驱动
|
主题 — NexT.Mist v5.1.3
|本站总访问量次