コード例 #1
0
ファイル: tensor.py プロジェクト: zqxyz73/dgl
def unsqueeze(input, dim):
    return np.unsqueeze(input, dim)
コード例 #2
0
g

h = torch.FloatTensor(1,5)
h

h = nn.Parameter(h)
h

"""#Squeeze ka eg:-"""

vinit = [[[[[1,2,3], [5,6,7]]]]]
import numpy as np
v = np.array(vinit)

v
v.shape

import numpy as np
vinit = np.squeeze(vinit)

vinit

vinit.shape

vinit = np.unsqueeze(0)(vinit)
vinit
vinit.shape

"""#Idhar tak squeeze"""

コード例 #3
0
train_loss = 0
valid_loss = 0
valid_loss_list, train_loss_list = [], []
for epoch in range(max_epochs):
    train_loss = 0
    valid_loss = 0

    for data in train_loader:
        batch_size = data.size()[0]

        #print (data.size())
        datav = Variable(data).cuda()
        l1 = random.randint(1, 100) - 1
        blb = lesion_generator()
        temp_img = (datav[l1, :, :, :])
        temp_img = np.unsqueeze(temp_img, 0).cpu().numpy()
        temp_img[blb > 0.1] = blb[blb > 0.1]
        datav[l1, :, :, :] = torch.from_numpy(temp_img)
        #datav[l2,:,row2:row2+5,:]=0

        mean, logvar, rec_enc = G(datav)
        if epoch % 5 == 0:
            beta_err = beta_loss_function(rec_enc, datav, mean, logvar, beta)
        else:
            beta_err = beta_loss_function(rec_enc, datav, mean, logvar, 0)
        err_enc = beta_err
        opt_enc.zero_grad()
        err_enc.backward()
        opt_enc.step()

    G.eval()