[docs]classSequentialPredictions:models_2d={}# TODOmodels_3d={'segformer':25,'unet':1,'vnet':1,# 'segformer': 2, Different path}dimensions=['3d']# '2d',len_battery_test=17def__call__(self):"""Method to run the models in sequence and parallel. """processes=[]fordimensioninself.dimensions:ifdimension=='2d':models=self.models_2delse:models=self.models_3dformodelinlist(models.keys()):gpu_memory=check_gpu_memory()# Verify GPU memorywhilegpu_memory<12124:# Wait until GPU memory is available 9124print("Need more GPU memory. Waiting...")time.sleep(55)gpu_memory=check_gpu_memory()print(f"\nTest {model} ({dimension})...")# Start model battery testtry:process=Process(target=self.run_model,args=(model,dimension,str(models[model])))process.start()processes.append(process)except:passtime.sleep(30)forprocessinprocesses:process.join()print("All models are tested")
[docs]@staticmethoddefrun_model(model,dimension,run_version):"""Function to run the model to predict the battery test. When the prediction is finished, the time with more parameters are saved in a json file. The place for the json file is in the respective folder results. Args: model (str): Name of the model dimension (str): Number of dimensions (2d or 3d) run_version (str): Version of the model """path='./resultsNew/'args=['--mode','Predict','--model',model,'--dimension',dimension,'--run_version',run_version,'--path_prediction',path,]cmd=['python3','train.py']+argstry:start_time=datetime.now()subprocess.run(cmd)end_time=datetime.now()elapsed_time=end_time-start_timeresult={'model':model,'dimension':dimension,'run_version':run_version,'total_batteries_tested':SequentialPredictions.len_battery_test,'start_time':start_time.strftime("%Y-%m-%d %H:%M:%S"),'end_time':end_time.strftime("%Y-%m-%d %H:%M:%S"),'elapsed_time':str(elapsed_time),}withopen(path+model+'_'+dimension+'/time_prediction_set.json','w')asjson_file:json.dump(result,json_file,indent=4)json_file.write(',\n')exceptExceptionase:print(e)