(tf_config=None, server=None)
| 667 | |
| 668 | |
| 669 | def main(tf_config=None, server=None): |
| 670 | # check dataset and count data set size |
| 671 | print("Checking dataset...") |
| 672 | train_file = args.data_location + '/local_train_splitByUser' |
| 673 | test_file = args.data_location + '/local_test_splitByUser' |
| 674 | if args.parquet_dataset and not args.tf: |
| 675 | train_file += '.parquet' |
| 676 | test_file += '.parquet' |
| 677 | if (not os.path.exists(train_file)) or (not os.path.exists(test_file)): |
| 678 | print("Dataset does not exist in the given data_location.") |
| 679 | sys.exit() |
| 680 | |
| 681 | no_of_training_examples = 0 |
| 682 | no_of_test_examples = 0 |
| 683 | if args.parquet_dataset and not args.tf: |
| 684 | import pyarrow.parquet as pq |
| 685 | no_of_training_examples = pq.read_table(train_file).num_rows |
| 686 | no_of_test_examples = pq.read_table(test_file).num_rows |
| 687 | else: |
| 688 | no_of_training_examples = sum(1 for line in open(train_file)) |
| 689 | no_of_test_examples = sum(1 for line in open(test_file)) |
| 690 | print("Numbers of training dataset is {}".format(no_of_training_examples)) |
| 691 | print("Numbers of test dataset is {}".format(no_of_test_examples)) |
| 692 | |
| 693 | # set batch size, eporch & steps |
| 694 | batch_size = math.ceil( |
| 695 | args.batch_size / args.micro_batch |
| 696 | ) if args.micro_batch and not args.tf else args.batch_size |
| 697 | |
| 698 | if args.steps == 0: |
| 699 | no_of_epochs = 1 |
| 700 | train_steps = math.ceil( |
| 701 | (float(no_of_epochs) * no_of_training_examples) / batch_size) |
| 702 | else: |
| 703 | no_of_epochs = math.ceil( |
| 704 | (float(batch_size) * args.steps) / no_of_training_examples) |
| 705 | train_steps = args.steps |
| 706 | test_steps = math.ceil(float(no_of_test_examples) / batch_size) |
| 707 | print("The training steps is {}".format(train_steps)) |
| 708 | print("The testing steps is {}".format(test_steps)) |
| 709 | |
| 710 | # set fixed random seed |
| 711 | tf.set_random_seed(args.seed) |
| 712 | |
| 713 | # set directory path for checkpoint_dir |
| 714 | model_dir = os.path.join(args.output_dir, |
| 715 | 'model_DIN_' + str(int(time.time()))) |
| 716 | checkpoint_dir = args.checkpoint if args.checkpoint else model_dir |
| 717 | print("Saving model checkpoints to " + checkpoint_dir) |
| 718 | |
| 719 | # create data pipline of train & test dataset |
| 720 | train_dataset = build_model_input(train_file, batch_size, no_of_epochs) |
| 721 | test_dataset = build_model_input(test_file, batch_size, 1) |
| 722 | |
| 723 | dataset_output_types = tf.data.get_output_types(train_dataset) |
| 724 | dataset_output_shapes = tf.data.get_output_shapes(test_dataset) |
| 725 | iterator = tf.data.Iterator.from_structure(dataset_output_types, |
| 726 | dataset_output_shapes) |
no test coverage detected