Lecture 031. 准备一个可以完整跑完的学习问题 · 实现代码
1. 准备一个可以完整跑完的学习问题 · 实现代码
按问题继续
真实CNN–GRU条件训练与greedy/beam生成、遮图/错图消融
展开完整实现代码
from pathlib import Path
import json, hashlib, platform, sys, time
from datetime import datetime, timezone
import numpy as np
from PIL import Image, ImageDraw
import matplotlib
if 'get_ipython' not in globals(): matplotlib.use('Agg')
import matplotlib.pyplot as plt
import torch
from torch import nn
import torch.nn.functional as F
OUT = Path('outputs/lab13'); OUT.mkdir(parents=True, exist_ok=True)
torch.set_num_threads(1)
torch.manual_seed(1303)
np.random.seed(1303)
START = time.perf_counter()
VOCAB = ['<pad>', '<bos>', '<eos>', 'a', 'red', 'blue', 'green', 'square', 'circle', 'on', 'left', 'right']
W = {s:i for i,s in enumerate(VOCAB)}
PAD, BOS, EOS = 0, 1, 2
COLORS = {'red':(220,55,55), 'blue':(45,95,225), 'green':(35,170,75)}
print('CPU', torch.__version__, 'seed 1303; no downloaded data or weights')