python how to iterate through images

pred input is 1* 2 * 256 * 256 tensor

    pred = pred.numpy()#tensor转为数组
    pred = np.squeeze(pred)#把第一维去掉
    pred = np.transpose(pred, [1, 2, 0])#改变 维度顺序  256 * 256 * 2
    pred0=pred[:,:,0] 取第一通道
    pred0 = pred0 * 10
    pred0 = np.array(pred0, np.uint8)#opencv显示的话 要转换为8位无符号整型
    with open('pred0.txt', 'w') as q:#打开文件
        for i in range(pred0.shape[0]):#遍历行
            for w in range(pred0.shape[1]):#遍历列
            #for c in range(pred0.shape[2])#这句话如果单通道不需要
                #if pred0[i,w]<8:
                #   print("notice",pred0[i,w])
                q.write("{0}   {1}  {2}\n".format(i,w,pred0[i,w]))

Guess you like

Origin blog.csdn.net/ALZFterry/article/details/109512673