-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtmp.py
More file actions
45 lines (37 loc) · 926 Bytes
/
Copy pathtmp.py
File metadata and controls
45 lines (37 loc) · 926 Bytes
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
'''
@author: jinglingzhiyu
'''
import torch
import torch.nn as nn
import numpy as np
percent = np.linspace(0, 100, 101)
print(percent)
# def my_loss(preds, labels):
# loss, loss_ = 0.0, 0.0
# for i in range(preds.shape[1]):
# pred = preds[:, i]
# loss += torch.exp(pred)
# for i in range(preds.shape[1]):
# pred = preds[:, i]
# loss_ += labels[:, i] * torch.exp(pred)
# loss = loss_ / loss
# loss = - torch.log(loss)
# return loss
#
# a = torch.Tensor([0.1, 0.2, 0.3]).unsqueeze(0)
# # b = torch.Tensor([1]).long()
# # cr = nn.CrossEntropyLoss()
# b = torch.Tensor([0.1, 0.7, 0.2]).unsqueeze(0)
# c = my_loss(a,b)
# print(c)
# b = np.random.rand()
# nums = 3
# b = int(b * nums)
# print(b)
# b = torch.sparse.torch.eye(8)
# a = torch.ones(10).long()
# b = b.index_select(0, a)
# print(b.shape)
# print(b)
# b = [int(x) for x in np.linspace(0, 10, 4)]
# print(b)