2018年3月11日日曜日

頭をひねって考え出したDefault Boxesの実装がChainerの実装と構造が一緒で嬉しい

screenを使ってjupyter notebookとか使ってると

セッションが切れても裏で動き続けているという裏技

2018年3月2日金曜日

pytorchでcudaのavailabilityを確かめる

TensorFlowがimportできなくなった。
全然DeepLearningが捗らないのでPyTorchを入れて動かしたらすっごくわかりやすかったから
今後PyTorchやろうかな。



>>> torch.cuda.is_available()
True


nvidia driver と CUDA と cudnn のインストールはここがわかりやすかったしPyTorchでちゃんと動くのでよかった
http://www.python36.com/install-tensorflow-using-official-pip-pacakage/
そもそものTensorFlowは動かないけど





>>> import tensorflow as tf
Illegal instruction (core dumped)
(dl) khatta@ubuntu:~$


同じ事象がCPUサーバーでも起きてたから、何かインストールするときに間違ってるんだと思う
どうしよう。。


PyTorchでDeepLearningできるからいいかな。。

2018年3月1日木曜日

jupyter notebook でmp4動画を流すやつ


すごい遅いです

import cv2
import matplotlib.pyplot as plt
from IPython import display
%matplotlib inline

cap = cv2.VideoCapture('video.mp4')

while(cap.isOpened()):
    try:
        ret, frame = cap.read()
        frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
        plt.imshow(frame)

        display.clear_output(wait=True)
        display.display(plt.gcf())

    except KeyboardInterrupt:
        cap.release()

誰からも返事もらえない
https://ja.stackoverflow.com/questions/42040/python-opencv-jupyter-で-mp4-動画をリアルタイムに再生したい

2018年2月23日金曜日

tf.scatter_ndでゼロ埋め式テンソルを一発で作る

 (10, 4) の形のテンソルを作る際に、10個のうち4個だけ該当するインデックスに対して値を埋めて、あとはゼロにしたいみたいなことがある。
numpy を使ってまっすぐやると


tensor = np.zeros((10, 4))
indices = [2, 5, 6, 9]
tensor[indices] = [1, 1, 1, 1]

# array([[ 0.,  0.,  0.,  0.],
#        [ 0.,  0.,  0.,  0.],
#        [ 1.,  1.,  1.,  1.],
#        [ 0.,  0.,  0.,  0.],
#        [ 0.,  0.,  0.,  0.],
#        [ 1.,  1.,  1.,  1.],
#        [ 1.,  1.,  1.,  1.],
#        [ 0.,  0.,  0.,  0.],
#        [ 0.,  0.,  0.,  0.],
#        [ 1.,  1.,  1.,  1.]])


tf.scatter_ndを使うと

indices = [[2], [5], [6], [9]]
updates = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]
shape = [10, 4]
tensor = tf.scatter_nd(indices, updates, shape)

with tf.Session() as sess:
    print(sess.run(tensor))

# [[0 0 0 0]
# [0 0 0 0]
# [1 1 1 1]
# [0 0 0 0]
# [0 0 0 0]
# [1 1 1 1]
# [1 1 1 1]
# [0 0 0 0]
# [0 0 0 0]
# [1 1 1 1]]


一発でとか言ったんですが大概でした