用的pytorch来训练deeplabv3+
在做deeplabv3+的过程中,我的训练图片是8位的,如下图:
8位的:
24位的:
这样虽然在训练过程中能够正常训练。但是在评估过程中会出错,所以决定将训练图片转成24位图,重新训练。最后结果也表明了,只要将训练图片转成24位后之后的评估可视化等都没有问题。
由于RGB的图片就为24位,则简单将图片利用PIL转为RGB格式即可
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Tue Oct 24 10:47:36 2018
@author: yxh
"""
import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
import os
import sys
import shutil
path='/home/yxh/caffe/examples/fcn/IMAGES/IMAGES/'
newpath='/home/yxh/caffe/examples/fcn/IMAGES/output/'
def turnto24(path):
files = os.listdir(path)
files = np.sort(files)
i=0
for f in files:
imgpath = path + f
img=Image.open(imgpath).convert('RGB')
dirpath = newpath
file_name, file_extend = os.path.splitext(f)
dst = os.path.join(os.path.abspath(dirpath), file_name + '.jpg')
img.save(dst)
turnto24(path)
关于Image的mode的转换链接可参考:
https://www.jianshu.com/p/2e9539bdc307