Main function of program for predicting similarity testset samples Parameters: - args -- Parsed command line arguments as object returned by ArgumentParser
(args)
| 192 | _i += 1 |
| 193 | |
| 194 | def main(args): |
| 195 | """ |
| 196 | Main function of program for predicting similarity testset samples |
| 197 | |
| 198 | Parameters: |
| 199 | - args -- Parsed command line arguments |
| 200 | as object returned by ArgumentParser |
| 201 | """ |
| 202 | if not os.path.exists(args.source_code): |
| 203 | sys.exit(f"Directory {args.source_code} with source code is not found") |
| 204 | if not os.path.exists(args.test): |
| 205 | sys.exit(f"File {args.test} with test pairs is not found") |
| 206 | if not os.path.exists(args.tokenizer): |
| 207 | sys.exit(f"Tokenizer {args.tokenizer} is not found") |
| 208 | if not os.path.exists(args.dnn): |
| 209 | sys.exit(f"Check point with dnn model {args.dnn} is not found") |
| 210 | ds = makeDataset(args.source_code, args.test, args.tokenizer) |
| 211 | labels = loadLabels(args.labels) |
| 212 | #Load trained DNN from TF checkpoint |
| 213 | dnn = tf.keras.models.load_model(args.dnn) |
| 214 | if labels is not None: |
| 215 | if ds[0].shape[0] == labels.shape[0]: |
| 216 | #Evaluate DNN accuracy on the testset |
| 217 | loss, acc = dnn.evaluate(ds, labels, verbose = args.progress) |
| 218 | print("\nEvaluation accuracy is {:5.2f}%".format(acc * 100)) |
| 219 | print("Evaluation loss is {:5.2f}".format(loss)) |
| 220 | else: |
| 221 | print(f"Numers of labels {labels.shape[0]} " + |
| 222 | f"and samples {ds[0].shape[0]} is different ") |
| 223 | print("Accuracy of DNN on this test cannot be evaluated") |
| 224 | #Compute probabilities of similarity predicted by DNN |
| 225 | prob = dnn.predict(ds, verbose = args.progress) |
| 226 | writePredictions(args.test, prob, args.predictions) |
| 227 | ############################################################################## |
| 228 | # Program arguments are described below |
| 229 | ############################################################################## |
no test coverage detected