• 大小: 1.31MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-10-04
  • 语言: Python
  • 标签:

资源简介

ST-GAN: 用于图像合成的空间变换生成对抗网络 (CVPR 2018)

资源截图

代码片段和文件信息

import numpy as np
import tensorflow as tf
import ostime
import warp

# load data
def load(opttest=False):
path = “dataset“
if test:
images = np.load(“{0}/image_test.npy“.format(path))
hasGlasses = np.load(“{0}/attribute_test.npy“.format(path))[:15]
else:
images = np.load(“{0}/image_train.npy“.format(path))
hasGlasses = np.load(“{0}/attribute_train.npy“.format(path))[:15]
images_0 = images[~hasGlasses]
images_1 = images[hasGlasses]
glasses = np.load(“{0}/glasses.npy“.format(path))
D = {
“image0“: images_0
“image1“: images_1
“glasses“: glasses
}
return D

# make training batch
def makeBatch(optdataPH):
N0 = len(data[“image0“])
N1 = len(data[“image1“])
NG = len(data[“glasses“])
randIdx0 = np.random.randint(N0size=[opt.batchSize])
randIdx1 = np.random.randint(N1size=[opt.batchSize])
randIdxG = np.random.randint(NGsize=[opt.batchSize])
# put data in placeholders
[imageBGfakeDataimageRealDataimageFGfake] = PH
batch = {
imageBGfakeData: data[“image0“][randIdx0]/255.0
imageRealData: data[“image1“][randIdx1]/255.0
imageFGfake: data[“glasses“][randIdxG]/255.0
}
return batch

# make test batch
def makeBatchEval(opttestImageglassesPH):
idxG = np.arange(opt.batchSize)
# put data in placeholders
[imageBGimageFG] = PH
batch = {
imageBG: np.tile(testImage[opt.batchSize111])
imageFG: glasses[idxG]/255.0
}
return batch

# generate perturbed image
def perturbBG(optimageData):
rot = opt.pertBG*tf.random_normal([opt.batchSize])
tx = opt.pertBG*tf.random_normal([opt.batchSize])
ty = opt.pertBG*tf.random_normal([opt.batchSize])
O = tf.zeros([opt.batchSize])
pPertBG = tf.stack([txrotOOty-rotOO]axis=1) if opt.warpType==“homography“ else \
  tf.stack([Orottx-rotOty]axis=1) if opt.warpType==“affine“ else None
pPertBGmtrx = warp.vec2mtrx(optpPertBG)
image = warp.transformCropImage(optimageDatapPertBGmtrx)
return image

history = [None0True]
# update history and group fake samples
def updateHistory(optnewFake):
if history[0] is None:
history[0] = np.ones([opt.histQsizeopt.Hopt.W3]dtype=np.float32)
history[0][:opt.batchSize] = newFake
history[1] = opt.batchSize
return newFake
else:
randIdx = np.random.permutation(opt.batchSize)
storeIdx = randIdx[:opt.histSize]
useIdx = randIdx[opt.histSize:]
# group fake samples
higrowing = history[1]history[2]
extractIdx = np.random.permutation(hi if growing else opt.histQsize)[:opt.histSize]
groupFake = np.concatenate([history[0][extractIdx]newFake[useIdx]]axis=0)
hinew = hi+opt.batchSize-opt.histSize
history[0][hi:hinew] = newFake[storeIdx]
history[1] = hinew
if hinew==opt.histQsize:
history[1] = 0
history[2] = False
return groupFake

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-04-10 19:31  spatial-transformer-GAN-master\
     文件         170  2019-04-10 19:31  spatial-transformer-GAN-master\.editorconfig
     文件        1157  2019-04-10 19:31  spatial-transformer-GAN-master\.gitignore
     文件        1071  2019-04-10 19:31  spatial-transformer-GAN-master\LICENSE
     文件        3945  2019-04-10 19:31  spatial-transformer-GAN-master\README.md
     文件     1265720  2019-04-10 19:31  spatial-transformer-GAN-master\cover.png
     目录           0  2019-04-10 19:31  spatial-transformer-GAN-master\glasses\
     文件        2746  2019-04-10 19:31  spatial-transformer-GAN-master\glasses\data.py
     目录           0  2019-04-10 19:31  spatial-transformer-GAN-master\glasses\dataset\
     文件       32011  2019-04-10 19:31  spatial-transformer-GAN-master\glasses\dataset\example_test.png
     文件      829536  2019-04-10 19:31  spatial-transformer-GAN-master\glasses\dataset\glasses.npy
     文件        2352  2019-04-10 19:31  spatial-transformer-GAN-master\glasses\eval_STGAN.py
     文件        4177  2019-04-10 19:31  spatial-transformer-GAN-master\glasses\graph.py
     文件        5263  2019-04-10 19:31  spatial-transformer-GAN-master\glasses\options.py
     文件        1195  2019-04-10 19:31  spatial-transformer-GAN-master\glasses\preprocess_celebA.py
     文件         100  2019-04-10 19:31  spatial-transformer-GAN-master\glasses\test.sh
     文件         144  2019-04-10 19:31  spatial-transformer-GAN-master\glasses\train.sh
     文件        5615  2019-04-10 19:31  spatial-transformer-GAN-master\glasses\train_Donly.py
     文件        7863  2019-04-10 19:31  spatial-transformer-GAN-master\glasses\train_STGAN.py
     文件        1788  2019-04-10 19:31  spatial-transformer-GAN-master\glasses\util.py
     文件        6108  2019-04-10 19:31  spatial-transformer-GAN-master\glasses\warp.py
     目录           0  2019-04-10 19:31  spatial-transformer-GAN-master\indoor\
     文件        6009  2019-04-10 19:31  spatial-transformer-GAN-master\indoor\data.py
     文件        2352  2019-04-10 19:31  spatial-transformer-GAN-master\indoor\eval_STGAN.py
     文件        4179  2019-04-10 19:31  spatial-transformer-GAN-master\indoor\graph.py
     文件        4580  2019-04-10 19:31  spatial-transformer-GAN-master\indoor\options.py
     文件        4685  2019-04-10 19:31  spatial-transformer-GAN-master\indoor\pretrain_homo.py
     目录           0  2019-04-10 19:31  spatial-transformer-GAN-master\indoor\render\
     文件           0  2019-04-10 19:31  spatial-transformer-GAN-master\indoor\render\README.md
     文件          63  2019-04-10 19:31  spatial-transformer-GAN-master\indoor\test.sh
     文件         167  2019-04-10 19:31  spatial-transformer-GAN-master\indoor\train.sh
............此处省略3个文件信息

评论

共有 条评论