[LAB 14 · 图像问答:视觉条件与问题先验](/course/notebooks/11d9f74871544a77b42024a9fe06b81a.html) # 1. 环境与有限问题接口 · 实现代码 [独立阅读](/course/notebook-blocks/924df89109464fed8b7817f3ebf2b233.html) 按问题继续 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) ```