예제 #1
0
파일: main.py 프로젝트: owenmx/pytorch_DANN
def main():
    source_train_loader = mnist.mnist_train_loader
    target_train_loader = mnistm.mnistm_train_loader

    if torch.cuda.is_available():
        get_free_gpu()
        print('Running GPU : {}'.format(torch.cuda.current_device()))
        encoder = model.Extractor().cuda()
        classifier = model.Classifier().cuda()
        discriminator = model.Discriminator().cuda()

        train.source_only(encoder, classifier, discriminator,
                          source_train_loader, target_train_loader, save_name)
        train.dann(encoder, classifier, discriminator, source_train_loader,
                   target_train_loader, save_name)

    else:
        print("There is no GPU -_-!")
예제 #2
0
def main():
    """Main function."""

    # create sensor reader
    #s1 = comm_serial.Reader("/dev/ttyS3")
    m1 = comm_mcast.Reader.getReader("224.0.0.1", 1234)

    # create model
    m = model.Extractor(m1.indicate, m1.getSegment)

    # create window
    v = app.App.get()
    time.sleep(2)

    # connect callbacks
    v.getReader = getReader
    v.getRecorder = getRecorder
    v.getExtractor = getExtractor
    v.getReplayer = getReplayer

    # run main loop
    v.mainloop()
예제 #3
0
import torch.nn.functional as F
import numpy as np
import model
import train


# In[ ]:

if __name__ == "__main__":
    data_S_H = pd.read_csv('data/normal_B_sample.csv')
    data_S_F = pd.read_csv('data/fault_B_sample.csv')
    data_T_H = pd.read_csv('data/normal_A_sample.csv')
    label_S = pd.read_csv('data/label_B.csv')
    epochs_A = 100
    epochs_B = 100
    extractor = model.Extractor()
    generator = model.Generator()
    
    classifier_1 = model.Classifier_1()
    classifier_2 = model.Classifier_2()
	
    LR_A = 0.00001
    LR_B = 0.00001
    extractor.load_state_dict(torch.load('1D_CNN.pkl')) 
    for i in range(50):
        print('All Net',i)
        
        train.Net_A(data_S_H,data_S_F,label_S,extractor,generator
                    ,classifier_1,epochs_A,LR_A,i)
        extractor.load_state_dict(torch.load('extractor.pkl'))
        generator.load_state_dict(torch.load('generator.pkl'))
예제 #4
0
    yphi = torch.tensor(yphi)

dataset = torch.utils.data.TensorDataset(xs, ys, yphi)

dataloader = torch.utils.data.DataLoader(dataset,
                                         batch_size=args.batch_size,
                                         shuffle=True,
                                         drop_last=True)
device = torch.device("cuda" if args.cuda else "cpu")

###############################################################################
# Build the model
###############################################################################

ntokens = 850
extractor = model.Extractor(args.model, ntokens, args.emsize, args.nhid,
                            args.nlayers, args.dropout).to(device)
decoder = model.Decoder(args.nhid, args.nview, args.dropout).to(device)
generator = model.Generator(args.emsize, args.noiseDim,
                            args.dropout).to(device)
discriminator = model.Discriminator(args.emsize, args.dropout).to(device)

criterionD1 = nn.CrossEntropyLoss()  # for D_S
criterionD2 = nn.BCELoss()  # for D_N
LocalityConstrains = nn.CosineEmbeddingLoss()

noiseDim = int(args.noiseDim)

real_label = 1
fake_label = 0

lr = args.lr
예제 #5
0
    shuffle=True)

source_loader = torch.utils.data.DataLoader(datasets.MNIST(
    "../dataset/mnist/",
    train=True,
    download=True,
    transform=transforms.Compose([
        transforms.Resize(28),
        transforms.ToTensor(),
        transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
    ])),
                                            batch_size=250,
                                            shuffle=True)

# network components
feature_extractor = model.Extractor()
class_classifier = model.Classifier()
domain_discriminator = model.Discriminator()

# train the model on GPU
feature_extractor.cuda()
class_classifier.cuda()
domain_discriminator.cuda()

# training criterion
# with the help  gradient reversal layer, it can perform min-max game using the same criterion
class_criterion = nn.NLLLoss()
domain_criterion = nn.NLLLoss()

# optimizer
'''