GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — DeepSC-Colab/main.py at master · vytorrennan/DeepSC-Colab Expand file tree/ Copy pathmain.pyMore file actions 66 lines (62 loc) · 2.83 KB / Copy pathmain.pyFile metadata and controls66 lines (62 loc) · 2.83 KB 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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 import json import os import tensorflow as tf from parameters import para_config from models.transceiver import Transeiver, Mine from dataset.dataloader import return_loader from utlis.trainer import train_step, eval_step from utlis.tools import SeqtoText, SNR_to_noise if __name__ == '__main__': # Set random seed args = para_config() tf.random.set_seed(args.seed) # Set Parameters # Load the vocab vocab = json.load(open(args.vocab_path, 'rb')) args.vocab_size = len(vocab['token_to_idx']) token_to_idx = vocab['token_to_idx'] args.pad_idx = token_to_idx["<PAD>"] args.start_idx = token_to_idx["<START>"] args.end_idx = token_to_idx["<END>"] StoT = SeqtoText(token_to_idx, args.end_idx) # Load dataset train_dataset, test_dataset = return_loader(args) # Build Model mine_net = Mine() net = Transeiver(args) # Define the optimizer optim_net = tf.keras.optimizers.Adam(learning_rate=args.lr, beta_1=0.9, beta_2=0.98, epsilon=1e-8) optim_mi = tf.keras.optimizers.Adam(learning_rate=0.001) # Training the model checkpoints = tf.train.Checkpoint(Transceiver=net) manager = tf.train.CheckpointManager(checkpoints, directory=args.checkpoint_path, max_to_keep=3) if args.resume_from_checkpoint: latest_checkpoint = tf.train.latest_checkpoint(args.checkpoint_path) if latest_checkpoint is not None: checkpoints.restore(latest_checkpoint) print('Resumed from checkpoint:', latest_checkpoint) else: print('No checkpoint found in {}. Starting from scratch.'.format(args.checkpoint_path)) # Training the entire net os.makedirs(args.checkpoint_path, exist_ok=True) best_loss = float('inf') for epoch in range(args.epochs): n_std = SNR_to_noise(args.train_snr) train_loss_record, test_loss_record = 0.0, 0.0 train_batches, test_batches = 0, 0 for (_, (inp, tar)) in enumerate(train_dataset): train_loss, train_loss_mine, _ = train_step(inp, tar, net, mine_net, optim_net, optim_mi, args.channel, n_std, train_with_mine=args.train_with_mine) train_loss_record += float(train_loss.numpy()) train_batches += 1 train_loss_record = train_loss_record / max(train_batches, 1) # Valid for (_, (inp, tar)) in enumerate(test_dataset): test_loss = eval_step(inp, tar, net, args.channel, n_std) test_loss_record += float(test_loss.numpy()) test_batches += 1 test_loss_record = test_loss_record / max(test_batches, 1) if best_loss > test_loss_record: best_loss = test_loss_record manager.save(checkpoint_number=epoch) print('Epoch {} Train Loss {:.4f} Test Loss {:.4f}'.format(epoch + 1, train_loss_record, test_loss_record)) |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |