示例#1
0
import torch
import torch.nn as nn
import torchvision
import torchvision.transforms as transforms
import torch.nn.functional as F
from LSImP import LoadSave
import os, os.path

loadsave = LoadSave()

DIRO = 'AnomTest/Original'
DIRP = 'AnomTest/Predicted'
DIRS = 'AnomTest/Test'
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
if torch.cuda.is_available():
    print('GPU')
else:
    print('CPU')
criterion = torch.nn.L1Loss()


def wholePictureLossAnom():
    loss = criterion(imageO, imageP)
    return loss


def oneKernelPictureLossAnom():
    for i in range(640):
        for j in range(480):
            loss = criterion(imageO[0][j][i], imageP[0][j][i])
            if loss > 0.05:
示例#2
0
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
import numpy as np
from LSImP import LoadSave
import os, os.path

DIRA = 'AnomTest/Anom'
DIRNA = 'AnomTest/NonAnom'
DIRP = 'AnomTest/Predicted'

ls = LoadSave()


class NeuralNetworkCalculator(nn.Module):
    def __init__(self):
        super(NeuralNetworkCalculator, self).__init__()
        self.layer_1 = nn.Conv3d(1,
                                 1,
                                 kernel_size=(1, 15, 15),
                                 stride=(1, 5, 5))  #kernel = 5 padding = 2
        self.layer_2 = nn.Conv3d(1,
                                 1,
                                 kernel_size=(1, 10, 10),
                                 stride=(1, 3, 3))  #kernel = 5 padding = 2
        self.layer_3 = nn.Conv3d(1, 1, kernel_size=(1, 7, 7),
                                 stride=(1, 1, 1))  #kernel = 5 padding = 2
        self.layer_4 = nn.Conv3d(1, 1, kernel_size=(1, 5, 9),
                                 stride=(1, 1, 1))  #kernel = 5 padding = 2
        self.layer_5 = nn.Conv3d(1, 1, kernel_size=(2, 5, 9),