1.
# 把x0和x1的数据合在一起,声明是什么类型的数据集
x = torch.cat((x0, x1), 0).type(torch.FloatTensor) # shape (200, 2) FloatTensor = 32-bit floating
y = torch.cat((y0, y1), ).type(torch.LongTensor) # shape (200,) LongTensor = 64-bit integer
2.
对于回归问题常用的损失函数有:均方误差(MSE),平均绝对值误差(也称L1损失)等。
对于分类问题,常用的损失函数则为交叉熵(Cross Entropy Loss)。
而交叉熵本质上描述的是两个概率分布的距离,即实际概率与期望概率之间的距离。这就不难理解:
交叉熵的值越小,两个概率分布就越接近,也就是预测值越接近期望值。
3. load数据
torch_dataset = Data.TensorDataset(x, y) # 告诉数据库训练数据是x, 计算loss的target是y
loader = Data.DataLoader(
dataset=torch_dataset,
batch_size=5,
shuffle=True, # 需不需要打乱数据顺序去训练
num_workers=2, # 提取的线程和进程数??
) # 使我们的训练值变成一小批一小批的
3. 生成当前的准确时间和时间戳
now = datetime.datetime.now(dateutil.tz.tzlocal()) # 生成当前的日期和时间
timestamp = now.strftime('%Y_%m_%d_%H_%M_%S') # 生成时间戳
output_dir = '../output/%s_%s_%s' % \
(cfg.DATASET_NAME, cfg.CONFIG_NAME, timestamp)