1. Why
平时都使用C++,偶尔需要用Python处理数据,运行tensorflow,因此记录某些函数、操作和问题
2. 一般用法
- 获取命令行参数:
image_path=str(sys.argv[1])
- 获取目录下的文件名:
labels = os.listdir(label_path)
- 排序:
labels.sort()
- 以空格分割:
str_list = line.split()
,取first = int(str_list[0])
- 文件复制:
from shutil import copyfile
,copyfile(“from”, "to")
- 去掉后四位:
str(label)[:-4]
- 调整图像大小:
shrink = cv2.resize(im, (320,240), interpolation=cv2.INTER_AREA)
3. tensorflow
3.1 操作
- 获取张量维度:
x.shape
3.2 问题
- could not convert string to float
- 使用
tf.gfile.FastGFile
读取图像,结果为byte string,不能直接feed,使用np.array(image)
会导致下个问题
- 使用
- ‘ascii’ codec can’t decode byte 0xff in position 0: ordinal not in range(128)
- python类型转换会经过Unicode,Unicode大小是128
- 使用cv2读取图像,根据网络输入调整数据维度