Predictions

Once you have a trained model, it can be used to generate predictions for new files.

Here, there are a series of tools which can be used to generate these predictions.

They are designed mostly to work from .map files, rather than directly from phase files. This is because the variety of combinations for phase files, cell info files, space group files etc. was judged to large to design a specific wrapper function. Instead, please see Conversions for how to generate .map before running these tools.

Command Line Tool

In many cases, both the original and inverse hands will be available and require predictions. This is useful because if the model cannot give a confident prediction for one map, it can provide a confident prediction for the other and the user can make their determination appropriately.

With this use case in mind, use topaz3.predict_from_maps to generate predictions and store them:

As with many Topaz3 tools, the tool can be run directly from the command line or with a yaml config file.

Raw predictions (per image) are generated for the original and inverse maps, then these predictions are averaged for each structure. Both sets of predictions are recorded in json files in the specified output directory.

If the output directory is not specified, the results will be printed to the terminal.

Example config file:

original_map_file: /path/to/maps/original.map
inverse_map_file: /path/to/maps/inverse.map
slices_per_axis: 20
model_file: /path/to/models/good_model.h5
output_dir: /record/predictions/here

Underlying Prediction Functions

topaz3.predictions.predict_original_inverse(original_map_file: str, inverse_map_file: str, slices_per_axis: int, model_file: str, output_dir: str = None, raw_pred_filename: str = 'raw_predictions.json', average_pred_filename: str = 'avg_predictions.json', rgb: bool = False) → <sphinx.ext.autodoc.importer._MockObject object at 0x7ff93cd63898>

Get predictions for the original and inverse maps at the same time and output results.

Slices both map files into 2d images, loads model from .h5 file and gets predictions on the image slices. These predictions are saved as raw_predictions.json, by default, in the output_dir.

The predictions are then averaged across each structure and these values are returned. They are also saved in avg_predictions.json, by default.

Parameters:
  • original_map_file – map file for original hand
  • inverse_map_file – map file for inverse hand
  • slices_per_axis – number of image slices to take along each axis to generate predictions
  • model_file – .h5 file to load Keras model from
  • output_dir – directory to output results files to
  • rgb – whether the model is expecting a 3 channel image
  • raw_pred_filename – set the filename for the raw predictions json output
  • average_pred_filename – set the filename for the average predictions json output
Returns:

numpy array with averaged predictions

topaz3.predictions.predictions_from_map(map_file: str, slices_per_axis: int, model_file: str, rgb: bool = False) → <sphinx.ext.autodoc.importer._MockObject object at 0x7ff93cd285c0>

Generate image slices from map file and get predictions from the model for each slice.

Return the raw image predictions as a numpy array.

Parameters:
  • map_file – map file to get predictions from
  • slices_per_axis – number of image slices to take along each axis to generate predictions
  • model_file – .h5 file to load Keras model from
  • rgb – indicate whether model expects 3 channel image
Returns:

numpy array with predictions for each image slice