tensorflow contrib cannot import name rnn

1
2
3
4
5
6
7
8
9
>>> from tensorflow.contrib import rnn
ImportError: cannot import name rnn
 
>>> import tensorflow as tf
>>> from tf.contrib import rnn
ImportError: No module named tf.contrib
 
>>> print tf.__version__
0.8.0

表示tensorflow的装的版本太低了,至少要装0.9.0版,比如装这个版本:

1
2
3
4
5
6
7
$ pip uninstall tensorflow
 
# Ubuntu/Linux 64-bit, CPU only, Python 2.7
$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.9.0-cp27-none-linux_x86_64.whl
 
# Python 2
$ sudo pip install --upgrade $TF_BINARY_URL

详情见:https://stackoverflow.com/questions/38386824/how-to-update-tensorflow-to-support-tf-contrib

再一点,新版的tensorflow只支持python3了,所以其实最简单的装tensorflow的方法是:

1
2
3
apt install pip3
 
pip3 install tensorflow

cmake增加调试选项

1
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")

指定安装路径

1
cmake -DCMAKE_INSTALL_PREFIX=path_to_install -DCMAKE_BUILD_TYPE=Release
1
set(CMAKE_INSTALL_PREFIX path_to_install)

明明有so却ldd没有

是因为少了这个命令:

1
export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH

生词之typo和globbing

typo:

打字时,按错键,打出错字,可以说打出typo了,很好记,就是type错打成typo了。

globbing:

计算机术语为通配符的意思。比如,cmake中,add_library命令中的路径名是不能用通配符的,必须先用cmake提供的file命令收集路径名到一个变量中,再将此变量赋给add_library,像这样:

1
2
3
4
5
6
7
8
file(GLOB srcs
	path1/example1/*.cpp
	path2/*.cpp
)
 
add_library(lib1
	${srcs}
)

看到其中的GLOB了没?

include_directories clean 清空

1,如果include_directories(dirA)写在add_subdirectory(dirB)之前,dirB目录的CMakeLists.txt会继承dirA的值。

2,如果include_directories(dirA)写在add_subdirectory(dirB)之后,dirB目录的CMakeLists.txt会不继承dirA的值。

所以所谓清空就是用方法2了。

placement new

代码直接在gcc里是可以编译通过的,在vc里编译,注意,如果是将例子代码加到MFC程序里,要注释掉源码中的DEBUG_NEW:

1
2
3
4
5
/*
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
*/

代码如下:

Read more

cannot open shared object file

1. setup LD_LIBRARY_PATH

1
export LD_LIBRARY_PATH=/where/you/install/lib:$LD_LIBRARY_PATH

2. modify /etc/ld.so.conf,add /where/you/install/lib, then

1
sudo ldconfig

cmake 显示编译命令

1
make VERBOSE=1

或者CMakeLists.txt中加上:

1
set(CMAKE_VERBOSE_MAKEFILE ON)

用tar备份linux文件系统

1
2
cd /
tar cvpjf backup.tar.bz2 --exclude=/proc --exclude=/lost+found --exclude=/backup.tar.bz2 --exclude=/mnt --exclude=/sys /