device = setup.init_seed() train_data = gmm_data.get_data() ###################################### visualize ############################################################### # create loader with data to iterate, batch size is 100 data_loader = torch.utils.data.DataLoader(train_data, batch_size=100, shuffle=True) # number of batches, 100000 / 100 = 1000 num_batches = len(data_loader) # start writing networks dis = model.DNet().float().to(device) # generate a funtion gen = model.GNet().float().to(device) # generate a function # hidden: torch.randn(size, 100) ################################################# loss function ############################################# criterion = nn.BCELoss().to( device ) # binary cross entropy loss, nothing fancy but a dirty way to compute the log lr = 0.01 ################################################# wrap the training as functions ################################ # the problem is a min-max optimization: min_G max_D log(D(x)) + log(1 - D(G(z))) # minimize -log(D(x)) - log (1 - D(G(z))), take one gradient descent step
TRAIN_FOLDER = '/home/alfarihfz/data/Pulmonary/train/' BATCH_SIZE=64 EPOCH = 500 DEVICE = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") def image_loader(path): return Image.open(path) transform = transforms.Compose( [ transforms.ToTensor(), ] ) gnet = model.GNet(device=DEVICE) hog = model.HOGLayer(device=DEVICE) trainData = datasets.DatasetFolder(root=TRAIN_FOLDER, loader=image_loader, extensions=['jpeg', 'png'], transform=transform) dataLoader = DataLoader(trainData, batch_size=BATCH_SIZE, shuffle=True) optimizer = torch.optim.Adam(gnet.parameters(), weight_decay=5e-4) criterion = torch.nn.MSELoss() for epoch in range(EPOCH): batch_loss = 0.0 for i, data in enumerate(dataLoader): img,_ = data
nargs='?', default='', help='Path to image folder. This is where the images from the run will be saved.' ) args = parser.parse_args() # check that model Keras version is same as local Keras version f = h5py.File(args.pred_model, mode='r') model_version = f.attrs.get('keras_version') keras_version = str(keras_version).encode('utf8') if model_version != keras_version: print('You are using Keras version ', keras_version, ', but the model was built using ', model_version) pred_model = model.GNet()._model pred_model.load_weights(args.pred_model) if args.image_folder != '': print("Creating image folder at {}".format(args.image_folder)) if not os.path.exists(args.image_folder): os.makedirs(args.image_folder) else: shutil.rmtree(args.image_folder) os.makedirs(args.image_folder) print("RECORDING THIS RUN ...") else: print("NOT RECORDING THIS RUN ...") # wrap Flask application with engineio's middleware app = socketio.Middleware(sio, app)