Ubuntu 16.04下同步github中fork出来的分支

githubfork出一些感觉比较好的项目,已经做了部分修改,由于某些原因,无法通过pull request合并到原作者的分支,但是想把原项目的最近更新代码合并进来,可以通过git fetch原始项目到本地,通过git merge的进行代码合并。

fork出来的pyseeta项目为例

  • 检出自己的代码
$ git checkout https://github.com/wangqiang1588/pyseeta.git
  • 把原作者项目地址添加到刚刚检出的项目
$ git remote add upstream https://github.com/TuXiaokang/pyseeta.git
  • 从原作者仓库获取到分支,及相关的提交信息
$ git fetch upstream
  • 切换到想合并代码的分支
$ git checkout master
  • 代码合并,并解决冲突
$ git merge upstream/master
  • 提交合并后的代码
$ git commit -m "merge ......."
  • 推送提交到远程服务器
$ git push

参考链接


如何同步 Github fork 出来的分支

TypeError: slice indices must be integers or None or have an __index__ method

执行如下Python脚本时

import numpy as np

dy = [0,1,2]
edy = [0,1,2]

dy[0:2] = np.fix(dy[0:2])
edy[0:2] = np.fix(edy[0:2])

box = [[1,2,3,4],[3,4,5,6]]

box2 = box[dy[0]:edy[2]]

会遇到错误信息

Traceback (most recent call last):
  File "test.py", line 11, in <module>
    box2 = box[dy[0]:edy[2]]
TypeError: slice indices must be integers or None or have an __index__ method

这个提示非常具有迷惑性,会让人不知所措。

其实非常简单

dy[0:2] = np.fix(dy[0:2])

这行导致整个数组变成了浮点数格式的数组,可以试着打印出结果,就会发现整个里面的数字完全变成了浮点数。

而浮点数是不可以用来作为数组的下标的。

修改成如下方式即可

import numpy as np

dy = [0,1,2]
edy = [0,1,2]

dy[0:2] = np.fix(dy[0:2])
edy[0:2] = np.fix(edy[0:2])

box = [[1,2,3,4],[3,4,5,6]]

box2 = box[int(dy[0]):int(edy[2])]

请注意最后的

int()

函数,强制转换浮点数为整数。

参考链接


错误异常slice indices must be integers or None or have

微软Xbox One S音频输出到普通喇叭

最近买了个微软Xbox One S国行版,结果到货后,非常悲剧的发现音频输出部分只支持HDMI跟光纤音箱的接口。注意:主机上那个貌似耳机插孔的地方,实际上是外置红外接收器的接口(接口附近有IR Input字样)Xbox One S自带的手柄上,有一个耳机的插孔,可以插上耳机,但是问题是,长时间带耳机会比较夹耳朵,因此还是用以前买的小喇叭最好了(本人对音质的追求不高)。

搜索了半天,在淘宝找到两个解决方法:

继续阅读微软Xbox One S音频输出到普通喇叭

Ubuntu 16.04命令行监视Nvidia显卡使用情况

在使用GPU做计算,比如跑Deep Learning代码的时候,我们可能希望能够实时检测显存的使用情况。

Nvidia自带了一个名为nvidia-smi的命令行工具,会显示显存使用情况,但这个命令行工具只能输出一次结果,不支持持续监控输出。

这时候就需要用到watch命令了.

继续阅读Ubuntu 16.04命令行监视Nvidia显卡使用情况

Ubuntu 16.04编译GPU(CUDA)版本的Caffe

  • 配置编译环境

参照Ubuntu 14.04,14.10,16.04编译CPU版本Caffe确保可以正常编译通过CPU版本的Caffe.

  • 安装Nvidia CUDA驱动

参照Ubuntu 16.04安装Nvidia CUDA驱动安装Nvidia CUDA驱动.

  • 安装Nvidia CUDNN库

参照Ubuntu 16.04开启dlib对于AVX或者CUDA的支持里面设置Nvidia CUDNN部分,配置好Nvidia CUDNN库.

  • 编译代码
$ cd caffe

$ cmake . -DCUDA_NVCC_FLAGS="-D_FORCE_INLINES"

$ make
  • 编译出错的处理

如果编译时候出现如下错误信息

/usr/include/string.h: In function ‘void* __mempcpy_inline(void*, const void*, size_t)’:
/usr/include/string.h:652:42: error: ‘memcpy’ was not declared in this scope
   return (char *) memcpy (__dest, __src, __n) + __n;
                                          ^
CMake Error at cuda_compile_generated_softmax_layer.cu.o.cmake:266 (message):
  Error generating file
  /home/longsky/Source/caffe/src/caffe/CMakeFiles/cuda_compile.dir/layers/./cuda_compile_generated_softmax_layer.cu.o


src/caffe/CMakeFiles/caffe.dir/build.make:469: recipe for target 'src/caffe/CMakeFiles/cuda_compile.dir/layers/cuda_compile_generated_softmax_layer.cu.o' failed
make[2]: *** [src/caffe/CMakeFiles/cuda_compile.dir/layers/cuda_compile_generated_softmax_layer.cu.o] Error 1
CMakeFiles/Makefile2:272: recipe for target 'src/caffe/CMakeFiles/caffe.dir/all' failed
make[1]: *** [src/caffe/CMakeFiles/caffe.dir/all] Error 2

则需要在执行cmake的时候增加

-DCUDA_NVCC_FLAGS="-D_FORCE_INLINES"

的定义。

  • 编译选项

某些库在使用Nvidia CUDNN的时候会崩溃,此时我们可以在编译的时候,排除Nvidia CUDNN即可。

例子如下:

$ cmake . -DCUDA_NVCC_FLAGS="-D_FORCE_INLINES" -DUSE_CUDNN=OFF

参考链接


ubuntu 16.04中CAFFE配置步骤

Python 2.7在调用自定义类函数时候报错"exceptions.TypeError: 'int' object is not callable"

Python 2.7中按照如下方式定义类

class Rectangle:

    def __init__(self,l):
        self.left = l

    def left(self):
        return self.left

if __name__ == '__main__':
    rect = Rectangle(1)
    print rect.left()

在执行脚本的时候会报告如下错误

Traceback (most recent call last):
  File "test.py", line 11, in <module>
    print rect.left()
TypeError: 'int' object is not callable

造成错误的原因在于Python 2.7中当类的成员变量跟方法名重名的时候,默认是使用类的成员变量,而成员变量是无法被调用的,因而导致报错。

解决方法就是避免方法名跟成员变量同名即可,比如上面的定义修改成如下方式即可

class Rectangle:

    def __init__(self,l):
        self.l = l

    def left(self):
        return self.l

if __name__ == '__main__':
    rect = Rectangle(1)
    print rect.left()