srez – super-resolution

https://github.com/david-gpu/srez

python3 srez_main.py --run demo.

报错

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/imageio/plugins/ffmpeg.py", line 82, in get_exe
    auto=False)
  File "/usr/local/lib/python3.5/dist-packages/imageio/core/fetching.py", line 102, in get_remote_file
    raise NeedDownloadError()
imageio.core.fetching.NeedDownloadError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "srez_main.py", line 1, in <module>
    import srez_demo
  File "/root/srez/srez_demo.py", line 1, in <module>
    import moviepy.editor as mpe
  File "/usr/local/lib/python3.5/dist-packages/moviepy/editor.py", line 22, in <module>
    from .video.io.VideoFileClip import VideoFileClip
  File "/usr/local/lib/python3.5/dist-packages/moviepy/video/io/VideoFileClip.py", line 3, in <module>
    from moviepy.video.VideoClip import VideoClip
  File "/usr/local/lib/python3.5/dist-packages/moviepy/video/VideoClip.py", line 21, in <module>
    from .io.ffmpeg_writer import ffmpeg_write_image, ffmpeg_write_video
  File "/usr/local/lib/python3.5/dist-packages/moviepy/video/io/ffmpeg_writer.py", line 11, in <module>
    from moviepy.config import get_setting
  File "/usr/local/lib/python3.5/dist-packages/moviepy/config.py", line 35, in <module>
    FFMPEG_BINARY = get_exe()
  File "/usr/local/lib/python3.5/dist-packages/imageio/plugins/ffmpeg.py", line 86, in get_exe
    raise NeedDownloadError('Need ffmpeg exe. '
imageio.core.fetching.NeedDownloadError: Need ffmpeg exe. You can download it by calling:
  imageio.plugins.ffmpeg.download()

修改

srez_demo.py

最上面加两行

import imageio
imageio.plugins.ffmpeg.download()

新建 checkpoint 文件夹,重新运行。

报错

Traceback (most recent call last):
 File "srez_main.py", line 190, in <module>
 tf.app.run()
 File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/platform/app.py", line 48, in run
 _sys.exit(main(_sys.argv[:1] + flags_passthrough))
 File "srez_main.py", line 185, in main
 _demo()
 File "srez_main.py", line 113, in _demo
 sess, summary_writer = setup_tensorflow()
 File "srez_main.py", line 103, in setup_tensorflow
 summary_writer = tf.train.SummaryWriter(FLAGS.train_dir, sess.graph)
AttributeError: module 'tensorflow.python.training.training' has no attribute 'SummaryWriter'

升级 tensorflow-gpu
/usr/bin/pip3 install –upgrade tensorflow-gpu

又报错

ImportError: libcudnn.so.6: cannot open shared object file: No such file or directory

参考 这篇文章

 

OpenCV 动态检测

10000 是检测灵敏度阈值,根据需要调整灵敏度。

#coding=utf-8
import cv2
import numpy as np
import usb.core
import usb.backend.libusb1
import requests
import time

cap = cv2.VideoCapture(1)
backend = usb.backend.libusb1.get_backend(find_library=lambda x: "/usr/lib/libusb-1.0.so")
 # 
dev = usb.core.find(idVendor=0x18e3, idProduct=0x5031, backend=backend)
dev.ctrl_transfer(0x21,0x01,0x0800,0x0600,[0x50,0xff])
dev.ctrl_transfer(0x21,0x01,0x0f00,0x0600,[0x00,0xf6])
dev.ctrl_transfer(0x21,0x01,0x0800,0x0600,[0x25,0x00])
dev.ctrl_transfer(0x21,0x01,0x0800,0x0600,[0x5f,0xfe])
dev.ctrl_transfer(0x21,0x01,0x0f00,0x0600,[0x00,0x03])
dev.ctrl_transfer(0x21,0x01,0x0f00,0x0600,[0x00,0x02])
dev.ctrl_transfer(0x21,0x01,0x0f00,0x0600,[0x00,0x12])
dev.ctrl_transfer(0x21,0x01,0x0f00,0x0600,[0x00,0x04])
dev.ctrl_transfer(0x21,0x01,0x0800,0x0600,[0x76,0xc3])
dev.ctrl_transfer(0x21,0x01,0x0a00,0x0600,[4,0x00])   

firstFrame = None

while(1):
        ret, frame = cap.read()
        frame = cv2.resize(frame, (1280, 480), interpolation=cv2.INTER_CUBIC)
        frame_left = frame[0:480,0:640]
        frame_right = frame[0:480,640:1280]
        gray = cv2.cvtColor(frame_left, cv2.COLOR_BGR2GRAY)         
        gray = cv2.GaussianBlur(gray, (21, 21), 0)
        if firstFrame is None:  
            firstFrame = gray
            continue
    
        frameDelta = cv2.absdiff(firstFrame, gray)
        thresh = cv2.threshold(frameDelta, 25, 255, cv2.THRESH_BINARY)[1] 
        thresh = cv2.dilate(thresh, None, iterations=2)
        (_, cnts, _) = cv2.findContours(thresh.copy(), cv2.RETR_CCOMP, cv2.CHAIN_APPROX_SIMPLE)
       
        g = frame.copy()
        ii = 0
        for c in cnts:
            if cv2.contourArea(c) < 10000:
                continue
            ii = 1
            #(x, y, w, h) = cv2.boundingRect(c)
            #print (cv2.contourArea(c))
            #cv2.rectangle(g, (x, y), (x + w, y + h), (0, 255, 0), 2)
        if ii == 1:
            url = "http://br.bj.oupeng.com:10080"
            t = time.time()
            cv2.imwrite("./"+str(t)+".jpg", g)
            files = {'file123':(str(t)+'.png',open("./"+str(t)+".jpg",'rb'))}
            data = {'time',str(t)}
            r = requests.post(url, files=files )#, data = data)
            print(r.text)
        cv2.imshow("br",g)
        firstFrame = gray.copy() 
        ##去掉绿色通道,生成红蓝图
        #zeros = np.zeros(frame_2.shape[:2], dtype = "uint8")
        #merged = cv2.merge([b,zeros,r2])  
        #cv2.imshow("br",merged)  
        
        if cv2.waitKey(1) & 0xFF == ord('q'):
                break
cap.release()
cv2.destroyAllWindows()

TOF python 实现

看了下  lighthouse ,图漾景深摄像头的原理。似乎是用 tof(time of fly) 和 光流实现的。

模拟一下

import cv2
import numpy as np
cap = cv2.VideoCapture(0)

ret, frame1 = cap.read()
prvs = cv2.cvtColor(frame1,cv2.COLOR_BGR2GRAY)
hsv = np.zeros_like(frame1)
hsv[...,1] = 255

while(1):
    ret, frame2 = cap.read()
    next = cv2.cvtColor(frame2,cv2.COLOR_BGR2GRAY)

    flow = cv2.calcOpticalFlowFarneback(prvs,next, None, 0.5, 3, 15, 3, 5, 1.2, 0)

    mag, ang = cv2.cartToPolar(flow[...,0], flow[...,1])
    hsv[...,0] = ang*180/np.pi/2
    hsv[...,2] = cv2.normalize(mag,None,0,255,cv2.NORM_MINMAX)
    rgb = cv2.cvtColor(hsv,cv2.COLOR_HSV2BGR)

    cv2.imshow('frame2',rgb)
    k = cv2.waitKey(30) & 0xff
    if k == 27:
        break
    elif k == ord('s'):
        cv2.imwrite('opticalfb.png',frame2)
        cv2.imwrite('opticalhsv.png',rgb)
    prvs = next

cap.release()
cv2.destroyAllWindows()

效果:

视频地址:https://m.youtube.com/watch?v=5jur04bJDkM&feature=youtu.be

MAgent 安装调试笔记

git clone git@github.com:geek-ai/MAgent.git
cd MAgent

brew install cmake llvm boost
brew install jsoncpp argp-standalone
brew tap david-icracked/homebrew-websocketpp
brew install --HEAD david-icracked/websocketpp/websocketpp

bash build.sh
export PYTHONPATH=$(pwd)/python:$PYTHONPATH

build 的时候报错

make[2]: /usr/local/opt/llvm/bin/clang++: No such file or directory/usr/local/opt/llvm/bin/clang++: No such file or directory

 

Efficient Deep Learning for Stereo Matching

一个基于 Siamese 结构的  Optical Flow 解决方案。

web:http://www.cs.toronto.edu/deepLowLevelVision/

GIT : https://bitbucket.org/saakuraa/cvpr16_stereo_public

闲言:《第一本无人驾驶技术书》第四章提到  Urtasun 教授的一个牛逼解决方案。0.3秒搞定一组双目视觉的深度图。找了下实现的代码,在 GitHub 找了好久,原来在  BBK上。

简单测试

th inference_match_subimg.lua -g 0 --model split_win37_dep9 --data_version kitti2015 --data_root pretrain/kitti2015/sample_img --model_param pretrain/kitti2015/param.t7 --bn_meanstd pretrain/kitti2015/bn_meanstd.t7 --saveDir outImg --start_id 1 --n 1

提前讲文件转为 png格式放在  pretrain/kitti2015/sample_img/image_2 & image_3

命名格式为  00000{num}_10.png   并改 –n 参数为 2

效果。速度比 pyflow 快了不少

Pyfolw的测试,测试原图也在这里

pix2code GUI转换为 iOS,android,web 页面源码

GITHUB:  https://github.com/tonybeltramelli/pix2code

操作流程见github,非常详细。

一路无话,在公司用 1070训,报

python3 ./train.py ../datasets/web/training_set ../bin
Using TensorFlow backend.
Loading data...
Generating sparse vectors...
Dataset size: 143741
Vocabulary size: 19
Input shape: (256, 256, 3)
Output size: 19
Convert arrays...
Traceback (most recent call last):
 File "./train.py", line 66, in <module>
 run(input_path, output_path, is_memory_intensive=use_generator, pretrained_model=pretrained_weigths)
 File "./train.py", line 24, in run
 dataset.convert_arrays()
 File "/root/code/pix2code/model/classes/dataset/Dataset.py", line 82, in convert_arrays
 self.input_images = np.array(self.input_images)
MemoryError

nvidia-smi 了下,发现有个进程占了2G显存。kill 之,重试还报一样的错误。

重新看了下 github 上的 readme

解决方案,用下面这个语句。也是官方推荐的train方式,之前没仔细看。

python3 ./train.py ../datasets/web/training_set ../bin 1

开始非常愉快的训练了。。。1080ti 大概 18分钟1轮,默认设定为 10轮。

一夜无话。。。。到早上终于训练好了

截了一张博客的图

生成 GUI

python3 ./sample.py ../bin pix2code  1.jpg  ../code

生成的GUI,似乎生成的是它演示的哪个页面。不是我提供的图。。奇怪。重新训一下试试。

header{
btn-inactive,btn-active
}
row{
single{
small-title,text,btn-green
}
}
row{
quadruple{
small-title,text,btn-orange
}
quadruple{
small-title,text,btn-orange
}
quadruple{
small-title,text,btn-orange
}
quadruple{
small-title,text,btn-orange
}
}
row{
double{
small-title,text,btn-orange
}
double{
small-title,text,btn-orange
}
}

忘了加  python3 ,默认用 python2 训完了报错

Traceback (most recent call last):
  File "./train.py", line 66, in <module>
    run(input_path, output_path, is_memory_intensive=use_generator, pretrained_m
odel=pretrained_weigths)
  File "./train.py", line 51, in run
    model.fit_generator(generator, steps_per_epoch=steps_per_epoch)
  File "/home/endler/code/pix2code/model/classes/model/pix2code.py", line 70, in
 fit_generator
    self.save()
  File "/home/endler/code/pix2code/model/classes/model/AModel.py", line 18, in s
ave
    self.model.save_weights("{}/{}.h5".format(self.output_path, self.name))
  File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 2
580, in save_weights
    raise ImportError('`save_weights` requires h5py.')
ImportError: `save_weights` requires h5py.

哭死,python2.7 没装  h5py。。。还得重训一次。。。。

gogogo,我就不信了。。。

又报这个,不过 权重文件已经生成了。

Exception ignored in: <bound method BaseSession.__del__ of <tensorflow.python.client.session.Session object at 0x7f3f6f67ae80>>
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 696, in __del__
TypeError: 'NoneType' object is not callable

反复试验了几次,貌似它只能识别 demo 哪几张图。ㄟ( ▔, ▔ )ㄏ