(tf_config=None, server=None)
| 329 | |
| 330 | |
| 331 | def main(tf_config=None, server=None): |
| 332 | # check dataset |
| 333 | print('Checking dataset') |
| 334 | train_file = args.data_location + '/train.csv' |
| 335 | test_file = args.data_location + '/eval.csv' |
| 336 | |
| 337 | if (not os.path.exists(train_file)) or (not os.path.exists(test_file)): |
| 338 | print( |
| 339 | '------------------------------------------------------------------------------------------' |
| 340 | ) |
| 341 | print( |
| 342 | "train.csv or eval.csv does not exist in the given data_location. Please provide valid path" |
| 343 | ) |
| 344 | print( |
| 345 | '------------------------------------------------------------------------------------------' |
| 346 | ) |
| 347 | sys.exit() |
| 348 | no_of_training_examples = sum(1 for line in open(train_file)) |
| 349 | no_of_test_examples = sum(1 for line in open(test_file)) |
| 350 | print("Numbers of training dataset is {}".format(no_of_training_examples)) |
| 351 | print("Numbers of test dataset is {}".format(no_of_test_examples)) |
| 352 | |
| 353 | # set params |
| 354 | # set batch size & steps |
| 355 | batch_size = args.batch_size |
| 356 | if args.steps == 0: |
| 357 | no_of_epochs = 10 |
| 358 | train_steps = math.ceil( |
| 359 | (float(no_of_epochs) * no_of_training_examples) / batch_size) |
| 360 | else: |
| 361 | no_of_epochs = math.ceil( |
| 362 | (float(batch_size) * args.steps) / no_of_training_examples) |
| 363 | train_steps = args.steps |
| 364 | test_steps = math.ceil(float(no_of_test_examples) / batch_size) |
| 365 | |
| 366 | # set fixed random seed |
| 367 | tf.set_random_seed(2021) |
| 368 | |
| 369 | # set directory path |
| 370 | model_dir = os.path.join(args.output_dir, |
| 371 | 'model_DeepFM_' + str(int(time.time()))) |
| 372 | checkpoint_dir = args.checkpoint if args.checkpoint else model_dir |
| 373 | print("Saving model checkpoints to " + checkpoint_dir) |
| 374 | |
| 375 | # create data pipline |
| 376 | wide_column, fm_column, deep_column = build_feature_cols() |
| 377 | train_dataset = generate_input_data(train_file, batch_size, no_of_epochs) |
| 378 | test_dataset = generate_input_data(test_file, batch_size, 1) |
| 379 | |
| 380 | iterator = tf.data.Iterator.from_structure(train_dataset.output_types, |
| 381 | test_dataset.output_shapes) |
| 382 | next_element = iterator.get_next() |
| 383 | |
| 384 | train_init_op = iterator.make_initializer(train_dataset) |
| 385 | test_init_op = iterator.make_initializer(test_dataset) |
| 386 | |
| 387 | # create variable partitioner for distributed training |
| 388 | num_ps_replicas = len(tf_config['ps_hosts']) if tf_config else 0 |
no test coverage detected