资源简介
该代码是CVPR2018一篇关于文本到图像合成的文章,经过测试可以使用
代码片段和文件信息
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from nltk.tokenize import RegexpTokenizer
from collections import defaultdict
from miscc.config import cfg
import torch
import torch.utils.data as data
from torch.autograd import Variable
import torchvision.transforms as transforms
import os
import sys
import numpy as np
import pandas as pd
from PIL import Image
import numpy.random as random
if sys.version_info[0] == 2:
import cPickle as pickle
else:
import pickle
def prepare_data(data):
imgs captions captions_lens class_ids keys = data
# sort data by the length in a decreasing order
sorted_cap_lens sorted_cap_indices = \
torch.sort(captions_lens 0 True)
real_imgs = []
for i in range(len(imgs)):
imgs[i] = imgs[i][sorted_cap_indices]
if cfg.CUDA:
real_imgs.append(Variable(imgs[i]).cuda())
else:
real_imgs.append(Variable(imgs[i]))
captions = captions[sorted_cap_indices].squeeze()
class_ids = class_ids[sorted_cap_indices].numpy()
# sent_indices = sent_indices[sorted_cap_indices]
keys = [keys[i] for i in sorted_cap_indices.numpy()]
# print(‘keys‘ type(keys) keys[-1]) # list
if cfg.CUDA:
captions = Variable(captions).cuda()
sorted_cap_lens = Variable(sorted_cap_lens).cuda()
else:
captions = Variable(captions)
sorted_cap_lens = Variable(sorted_cap_lens)
return [real_imgs captions sorted_cap_lens
class_ids keys]
def get_imgs(img_path imsize bbox=None
transform=None normalize=None):
img = Image.open(img_path).convert(‘RGB‘)
width height = img.size
if bbox is not None:
r = int(np.maximum(bbox[2] bbox[3]) * 0.75)
center_x = int((2 * bbox[0] + bbox[2]) / 2)
center_y = int((2 * bbox[1] + bbox[3]) / 2)
y1 = np.maximum(0 center_y - r)
y2 = np.minimum(height center_y + r)
x1 = np.maximum(0 center_x - r)
x2 = np.minimum(width center_x + r)
img = img.crop([x1 y1 x2 y2])
if transform is not None:
img = transform(img)
ret = []
if cfg.GAN.B_DCGAN:
ret = [normalize(img)]
else:
for i in range(cfg.TREE.BRANCH_NUM):
# print(imsize[i])
if i < (cfg.TREE.BRANCH_NUM - 1):
re_img = transforms.Scale(imsize[i])(img)
else:
re_img = img
ret.append(normalize(re_img))
return ret
class TextDataset(data.Dataset):
def __init__(self data_dir split=‘train‘
base_size=64
transform=None target_transform=None):
self.transform = transform
self.norm = transforms.Compose([
transforms.ToTensor()
transforms.Normalize((0.5 0.5 0.5) (0.5 0.5 0.5))])
self.target_transform = target_transform
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-05-07 00:12 AttnGAN-master\
文件 59 2018-05-07 00:12 AttnGAN-master\.gitignore
目录 0 2018-05-07 00:12 AttnGAN-master\DAMSMencoders\
文件 14 2018-05-07 00:12 AttnGAN-master\DAMSMencoders\.gitignore
文件 1063 2018-05-07 00:12 AttnGAN-master\LICENSE
文件 4461 2018-05-07 00:12 AttnGAN-master\README.md
目录 0 2018-05-07 00:12 AttnGAN-master\code\
文件 17 2018-05-07 00:12 AttnGAN-master\code\.gitignore
文件 4091 2018-05-07 00:12 AttnGAN-master\code\GlobalAttention.py
目录 0 2018-05-07 00:12 AttnGAN-master\code\cfg\
目录 0 2018-05-07 00:12 AttnGAN-master\code\cfg\DAMSM\
文件 569 2018-05-07 00:12 AttnGAN-master\code\cfg\DAMSM\bird.yml
文件 552 2018-05-07 00:12 AttnGAN-master\code\cfg\DAMSM\coco.yml
文件 657 2018-05-07 00:12 AttnGAN-master\code\cfg\bird_attn2.yml
文件 678 2018-05-07 00:12 AttnGAN-master\code\cfg\bird_attnDCGAN2.yml
文件 675 2018-05-07 00:12 AttnGAN-master\code\cfg\coco_attn2.yml
文件 453 2018-05-07 00:12 AttnGAN-master\code\cfg\eval_bird.yml
文件 462 2018-05-07 00:12 AttnGAN-master\code\cfg\eval_bird_attnDCGAN2.yml
文件 433 2018-05-07 00:12 AttnGAN-master\code\cfg\eval_coco.yml
文件 11122 2018-05-07 00:12 AttnGAN-master\code\datasets.py
文件 5185 2018-05-07 00:12 AttnGAN-master\code\main.py
目录 0 2018-05-07 00:12 AttnGAN-master\code\miscc\
文件 70 2018-05-07 00:12 AttnGAN-master\code\miscc\__init__.py
文件 2542 2018-05-07 00:12 AttnGAN-master\code\miscc\config.py
文件 8135 2018-05-07 00:12 AttnGAN-master\code\miscc\losses.py
文件 11025 2018-05-07 00:12 AttnGAN-master\code\miscc\utils.py
文件 21623 2018-05-07 00:12 AttnGAN-master\code\model.py
文件 10747 2018-05-07 00:12 AttnGAN-master\code\pretrain_DAMSM.py
文件 22725 2018-05-07 00:12 AttnGAN-master\code\trainer.py
目录 0 2018-05-07 00:12 AttnGAN-master\data\
文件 14 2018-05-07 00:12 AttnGAN-master\data\.gitignore
............此处省略24个文件信息
相关资源
- Unfold3D Networking v9.0.2 Build 2457汉化版
- 中文翻译版Neural Networks and Deep Learni
- (全网首发) Computer Organization and A
- Neural Networks and Deep Learning(中文版)
- Networks: An Introduction
- Docker Networking Cookbook PDF
- 基于VHDL的FPGA和Nios+II精炼_.pdf
- 计算机网络自顶向下方法第七版 Com
- 使用tensorflow实现CNN-RNN-GAN代码
- Parallel Computer Organization and Design 并行
- The Practice of System and Network Administrat
- 基于RNN的Tensorflow实现文本分类任务的
- Neural Networks and Deep Learning-神经网络与
- GAN生成手写数字
- David_A._Patterson_John_L._Hennessy_Computer_O
- ComputerOrganizationandDesign5th.pdf
- 无人机网络与通讯英文pdf文字版,
- ChargePumpCircuitDesign[PanFengandSamaddarTapa
- 神经网络设计Martin T.Hagan.pdf
- proneta_2_2_0_12 西门子profinet 网络诊断
- [计算机网络第五版]计算机网络第五版
- 启示录-打造用户喜爱的产品 MARTY CA
- zw_USB-over-network5.02.zip
- Windows网络编程第二版真正的高清带书
- 计算机网络系统方法,第五版(英文
- 李宏毅GAN对抗生成网络2018最新ppt全套
- GAN图像转换学术分享ppt
- (高清原版)Neural Networks and Learning
- 网络、群体与市场中文版.pdf,Networ
- Computer Networking A Top-Down Approach (7th
评论
共有 条评论