forked from CCC-123/Hydraplus_Net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cal_weight.py
64 lines (45 loc) · 1.2 KB
/
cal_weight.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import os
import torch
import torch.utils.data as data
from PIL import Image
import matplotlib.pyplot as plt
import torch.utils
import torchvision
import torch.nn as nn
import torchvision.transforms as transforms
import math
import dataload
mytransform = transforms.Compose([
transforms.ToTensor(),
]
)
set = dataload.myImageFloder(root = "./data/PA-100K/release_data/release_data",
label = "./data/PA-100K/annotation/annotation.mat",
transform = mytransform,
mode = 'train' )
imgLoader = torch.utils.data.DataLoader(
set,
batch_size= 1, shuffle= True, num_workers= 2)
print("image numbers %s" %len(set))
count = 0
dataiter = iter(imgLoader)
P = [0.0] * 26
N = [0.0] * 26
while count < 80000:
images,labels = dataiter.next()
for i in range(26):
if labels[0][i] == 1:
P[i] = P[i] + 1
else :
N[i] = N[i] + 1
count = count + 1
print(P)
print(N)
w = []
for i in range(26):
w.append(math.pow(math.e,N[i]/80000.0))
print(w)
f = open("loss weight",'w')
for weight in w:
f.write("%f "%weight)
f.close()