我需要将动态值分配给 JavaScript 字典以用于 echarts,但是在将动态值分配给字典时,它显示的行为与分配 s 相比有所不同......
我需要将动态值分配给 JavaScript 字典以用于 echarts,但是当将动态值分配给字典时,它显示的行为与分配静态值不同。
分配静态值时:
response = {
"stacks": {"5G_L2": [{"Open": "43"},{"Close": "24"}],
"5G_L3": [{"Open": "12"},{"Close": "2"}]
}
};
调试窗口显示如下:
而当动态分配值时,如下所示:
var datastck=[];
var serverdata = '{{ barCdata | tojson }}';
resPbar = $.parseJSON(serverdata);
$.each(resPbar, function (i, item) {
var di={};
di[item.Team]=[{"Open": item.Open},{"Close": item.Close}];
datastck.push(di);
});
response = {
"stacks": datastck
};
调试窗口如下:
它添加了一个额外的数组层。我需要有静态分配结构来支持 echarts,请有人提供建议?
提前致谢。
我编写了一个函数来获取验证准确性def 评估(loader,model,device):model.eval()model.to(device)correct = 0 total = len(loader.dataset)for data in loader...
我编写了一个函数来获取验证准确率
def evaluation(loader, model, device):
model.eval()
model.to(device)
correct = 0
total = len(loader.dataset)
for data in loader:
with torch.no_grad():
inputs, labels = data[0].to(device), data[1].to(device)
pred = model(inputs)
pred = pred.argmax(dim=1)
correct += pred.eq(labels).sum().item()
acc = correct / total
return acc
但当我测试它时,我发现 for 循环被跳过了。为什么?我的加载器和数据集在这张图中,请 在此处输入图片说明
数据加载器代码:
data_list = list(range(0, len(dataset)))
val_list = random.sample(data_list, int(len(dataset) * val_split))
trainset = [dataset[i] for i in data_list if i not in val_list]
valset = [dataset[i] for i in data_list if i in val_list]
# Weighed Sampling
if weighted_sampling:
label_count = Counter([int(data[1]) for data in dataset])
weights = [100 / label_count[int(data[1])] for data in trainset]
sampler = WeightedRandomSampler(weights, num_samples=len(trainset), replacement=True)
train_loader = DataLoader(trainset, batch_size=batch_size, sampler=sampler, drop_last=True)
else:
train_loader = DataLoader(trainset, batch_size=batch_size, shuffle=False, drop_last=True)
val_loader = DataLoader(valset, batch_size=batch_size, shuffle=True, drop_last=True)
我尝试检查我的数据集和数据加载器,但没有发现任何错误。我期待原因,谢谢