1 Star 0 Fork 0

东方佑/AMGAN

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
utils.py 1.56 KB
一键复制 编辑 原始数据 按行查看 历史
GuangyuanHao 提交于 2018-01-08 22:22 . update
from __future__ import division
import math
import json
import random
import pprint
import scipy.misc
import numpy as np
import copy
import os
from scipy.io import loadmat as loadimage
import numpy as np
import scipy
from skimage import feature
from PIL import Image
import cv2
def load_data(array):
n =array.shape[0]
size = array[0][0].shape
imgA = array[0][0].reshape(1,size[0],size[1],size[2])
for i in range(n-1):
imgA = np.concatenate((imgA,array[i+1][0].reshape(1,size[0],size[1],size[2])),axis=0)
return imgA/127.5-1.0
def rgb2gray(rgb):
return np.dot(rgb[...,:3],[0.299, 0.587, 0.144])
def load_label(array):
n =array.shape[0]
hot_code = np.zeros(10).reshape(1,10)
hot_code[0][array[0][1]]=1
labelA = hot_code
for i in range(n-1):
hot_code = np.zeros(10).reshape(1, 10)
hot_code[0][array[i+1][1]] = 1
labelA = np.concatenate((labelA,hot_code),axis=0)
return labelA
# ____________________________________________________
def save_images(image, size, path):
return imsave(inverse_transform(image), size, path)
def imsave(image, size, path):
return scipy.misc.imsave(path, merge(image, size), format='png')
def merge(image, size):
[n, h, w, c] = image.shape
image = image.reshape(n * h, w, c).astype(np.float)
if c == 1:
image = image.reshape(n * h, w)
img = image[:h * size[0]]
for i in range(size[1] - 1):
img = np.concatenate((img, image[(i + 1) * h * size[0]:(i + 2) * h * size[0]]), axis=1)
return img
def inverse_transform(image):
return (image+1.)/2.
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/chenyang918/AMGAN.git
git@gitee.com:chenyang918/AMGAN.git
chenyang918
AMGAN
AMGAN
master

搜索帮助

D67c1975 1850385 1daf7b77 1850385