Load pretrained model from file
(path, model, use_ideep)
| 135 | |
| 136 | |
| 137 | def LoadModel(path, model, use_ideep): |
| 138 | ''' |
| 139 | Load pretrained model from file |
| 140 | ''' |
| 141 | log.info("Loading path: {}".format(path)) |
| 142 | meta_net_def = pred_exp.load_from_db(path, 'minidb') |
| 143 | init_net = core.Net(pred_utils.GetNet( |
| 144 | meta_net_def, predictor_constants.GLOBAL_INIT_NET_TYPE)) |
| 145 | predict_init_net = core.Net(pred_utils.GetNet( |
| 146 | meta_net_def, predictor_constants.PREDICT_INIT_NET_TYPE)) |
| 147 | |
| 148 | if use_ideep: |
| 149 | predict_init_net.RunAllOnIDEEP() |
| 150 | else: |
| 151 | predict_init_net.RunAllOnGPU() |
| 152 | if use_ideep: |
| 153 | init_net.RunAllOnIDEEP() |
| 154 | else: |
| 155 | init_net.RunAllOnGPU() |
| 156 | |
| 157 | assert workspace.RunNetOnce(predict_init_net) |
| 158 | assert workspace.RunNetOnce(init_net) |
| 159 | |
| 160 | # Hack: fix iteration counter which is in CUDA context after load model |
| 161 | itercnt = workspace.FetchBlob("optimizer_iteration") |
| 162 | workspace.FeedBlob( |
| 163 | "optimizer_iteration", |
| 164 | itercnt, |
| 165 | device_option=core.DeviceOption(caffe2_pb2.CPU, 0) |
| 166 | ) |
| 167 | |
| 168 | |
| 169 | def RunEpoch( |
no test coverage detected
searching dependent graphs…