Lecture 03 学习讲义
正文
工具
按问题查找
Lecture 031. 环境与有限问题接口 · 实现代码

1. 环境与有限问题接口 · 实现代码

独立阅读

按问题继续

RGB+问题输入、question-only对照、同图换问与同问换图

展开完整实现代码
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/lab14');OUT.mkdir(parents=True,exist_ok=True)
torch.set_num_threads(1);torch.manual_seed(1403);np.random.seed(1403);START=time.perf_counter()
COLORS={'red':(220,55,55),'blue':(45,95,225),'green':(35,170,75)}
QUESTIONS=['how many objects?','what color is the leftmost object?','what shape is the rightmost object?']
ANSWERS=['one','two','red','blue','green','square','circle']; A={x:i for i,x in enumerate(ANSWERS)}
print('CPU',torch.__version__,'seed 1403; answer vocabulary:',ANSWERS)