(tf_config=None, server=None)
| 684 | |
| 685 | |
| 686 | def main(tf_config=None, server=None): |
| 687 | # check dataset and count data set size |
| 688 | print("Checking dataset...") |
| 689 | train_file = args.data_location + '/taobao_train_data' |
| 690 | test_file = args.data_location + '/taobao_test_data' |
| 691 | if args.parquet_dataset and not args.tf: |
| 692 | train_file += '.parquet' |
| 693 | test_file += '.parquet' |
| 694 | if (not os.path.exists(train_file)) or (not os.path.exists(test_file)): |
| 695 | print("Dataset does not exist in the given data_location.") |
| 696 | sys.exit() |
| 697 | no_of_training_examples = 0 |
| 698 | no_of_test_examples = 0 |
| 699 | if args.parquet_dataset and not args.tf: |
| 700 | import pyarrow.parquet as pq |
| 701 | no_of_training_examples = pq.read_table(train_file).num_rows |
| 702 | no_of_test_examples = pq.read_table(test_file).num_rows |
| 703 | else: |
| 704 | no_of_training_examples = sum(1 for line in open(train_file)) |
| 705 | no_of_test_examples = sum(1 for line in open(test_file)) |
| 706 | print("Numbers of training dataset is {}".format(no_of_training_examples)) |
| 707 | print("Numbers of test dataset is {}".format(no_of_test_examples)) |
| 708 | |
| 709 | # set batch size, eporch & steps |
| 710 | batch_size = math.ceil( |
| 711 | args.batch_size / args.micro_batch |
| 712 | ) if args.micro_batch and not args.tf else args.batch_size |
| 713 | |
| 714 | if args.steps == 0: |
| 715 | no_of_epochs = 100 |
| 716 | train_steps = math.ceil( |
| 717 | (float(no_of_epochs) * no_of_training_examples) / batch_size) |
| 718 | else: |
| 719 | no_of_epochs = math.ceil( |
| 720 | (float(batch_size) * args.steps) / no_of_training_examples) |
| 721 | train_steps = args.steps |
| 722 | test_steps = math.ceil(float(no_of_test_examples) / batch_size) |
| 723 | print("The training steps is {}".format(train_steps)) |
| 724 | print("The testing steps is {}".format(test_steps)) |
| 725 | |
| 726 | # set fixed random seed |
| 727 | tf.set_random_seed(args.seed) |
| 728 | |
| 729 | # set directory path for checkpoint_dir |
| 730 | model_dir = os.path.join(args.output_dir, |
| 731 | 'model_BST_' + str(int(time.time()))) |
| 732 | checkpoint_dir = args.checkpoint if args.checkpoint else model_dir |
| 733 | print("Saving model checkpoints to " + checkpoint_dir) |
| 734 | |
| 735 | # create data pipline of train & test dataset |
| 736 | train_dataset = build_model_input(train_file, batch_size, no_of_epochs) |
| 737 | test_dataset = build_model_input(test_file, batch_size, 1) |
| 738 | |
| 739 | dataset_output_types = tf.data.get_output_types(train_dataset) |
| 740 | dataset_output_shapes = tf.data.get_output_shapes(test_dataset) |
| 741 | iterator = tf.data.Iterator.from_structure(dataset_output_types, |
| 742 | dataset_output_shapes) |
| 743 | next_element = iterator.get_next() |
no test coverage detected