There are four evaluation modes: 1.only eval a .pth model: -e *.pth 2.only eval a certain epoch: -e epoch 3.eval all epochs in a given section: -e start_epoch-end_epoch 4.eval all epochs from a certain started epoch: -e start_epoch-
(self, model_path, model_indice, log_file, log_file_link)
| 54 | self.show_image = show_image |
| 55 | |
| 56 | def run(self, model_path, model_indice, log_file, log_file_link): |
| 57 | """There are four evaluation modes: |
| 58 | 1.only eval a .pth model: -e *.pth |
| 59 | 2.only eval a certain epoch: -e epoch |
| 60 | 3.eval all epochs in a given section: -e start_epoch-end_epoch |
| 61 | 4.eval all epochs from a certain started epoch: -e start_epoch- |
| 62 | """ |
| 63 | if ".pth" in model_indice: |
| 64 | models = [ |
| 65 | model_indice, |
| 66 | ] |
| 67 | elif "-" in model_indice: |
| 68 | start_epoch = int(model_indice.split("-")[0]) |
| 69 | end_epoch = model_indice.split("-")[1] |
| 70 | |
| 71 | models = os.listdir(model_path) |
| 72 | models.remove("epoch-last.pth") |
| 73 | sorted_models = [None] * len(models) |
| 74 | model_idx = [0] * len(models) |
| 75 | |
| 76 | for idx, m in enumerate(models): |
| 77 | num = m.split(".")[0].split("-")[1] |
| 78 | model_idx[idx] = num |
| 79 | sorted_models[idx] = m |
| 80 | model_idx = np.array([int(i) for i in model_idx]) |
| 81 | |
| 82 | down_bound = model_idx >= start_epoch |
| 83 | up_bound = [True] * len(sorted_models) |
| 84 | if end_epoch: |
| 85 | end_epoch = int(end_epoch) |
| 86 | assert start_epoch < end_epoch |
| 87 | up_bound = model_idx <= end_epoch |
| 88 | bound = up_bound * down_bound |
| 89 | model_slice = np.array(sorted_models)[bound] |
| 90 | models = [os.path.join(model_path, model) for model in model_slice] |
| 91 | else: |
| 92 | if os.path.exists(model_path): |
| 93 | models = [ |
| 94 | os.path.join(model_path, "epoch-%s.pth" % model_indice), |
| 95 | ] |
| 96 | else: |
| 97 | models = [None] |
| 98 | |
| 99 | results = open(log_file, "a") |
| 100 | link_file(log_file, log_file_link) |
| 101 | |
| 102 | for model in models: |
| 103 | logger.info("Load Model: %s" % model) |
| 104 | self.val_func = load_model(self.network, model) |
| 105 | if len(self.devices) == 1: |
| 106 | result_line = self.single_process_evalutation() |
| 107 | else: |
| 108 | result_line = self.multi_process_evaluation() |
| 109 | |
| 110 | results.write("Model: " + model + "\n") |
| 111 | results.write(result_line) |
| 112 | results.write("\n") |
| 113 | results.flush() |
no test coverage detected