Skip to main content
. 2023 Jul 7;23(13):6227. doi: 10.3390/s23136227
Algorithm 1 Inference Time Calculation
  1: procedure calculateInferenceTime(model, Xtest)
  2:      Variables:
  3:         input_data, start_time, prediction_inference_time, mean_time: float;
  4:         times: list;
  5:         i: int;
  6:    
  7:      for ilength(Xtest) do
  8:            input_data=Xtest[i] ▹ Get the input data for the current sample
  9:            input_data=np.newaxis(input_data,axis=0) ▹ Reshape the input to match the expected shape
 10:            start_time=time.perf_counter() ▹ Record the start time
 11:            prediction=model.predict(input_data) ▹ Perform the forward pass to get the prediction
 12:            inference_time=time.perf_counter()start_time ▹ Calculate the inference time
 13:            times.append(inference_time×1000) ▹ Append the inference time to the list
 14:      end for
 15:      mean_time=np.mean(times) ▹ Calculate the mean inference time
 16:      std_time=np.std(times) ▹ Calculate the standard deviation of inference times
 17:      return mean_time, std_time
 18: end procedure