* Enhancements for XFEL
* Enhancements for EIGER * Writer is more flexible and capable of handling DECTRIS data
This commit is contained in:
@@ -5,27 +5,21 @@
|
||||
#include <cmath>
|
||||
#include "../common/JFJochException.h"
|
||||
|
||||
NeuralNetResPredictor::NeuralNetResPredictor(const DiffractionExperiment &in_experiment)
|
||||
: experiment(in_experiment), model_input(512*512)
|
||||
NeuralNetResPredictor::NeuralNetResPredictor(const std::string& model_path)
|
||||
: model_input(512*512)
|
||||
#ifdef JFJOCH_USE_TORCH
|
||||
, device(torch::kCUDA)
|
||||
#endif
|
||||
{
|
||||
float max_direction = std::max(in_experiment.GetXPixelsNum(), in_experiment.GetYPixelsNum()) / 2.0;
|
||||
pool_factor = std::lround(max_direction / 512.0f);
|
||||
if (pool_factor <= 0)
|
||||
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "Detector size is too small");
|
||||
|
||||
if (pool_factor > 8)
|
||||
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "Detector size is too large");
|
||||
#ifdef JFJOCH_USE_TORCH
|
||||
module = torch::jit::load(experiment.GetNeuralNetModelPath());
|
||||
module = torch::jit::load(model_path);
|
||||
module.to(device);
|
||||
#endif
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void NeuralNetResPredictor::PrepareInternal(const T* image) {
|
||||
void NeuralNetResPredictor::PrepareInternal(const DiffractionExperiment& experiment, const T* image) {
|
||||
size_t pool_factor = GetMaxPoolFactor(experiment);
|
||||
size_t xpixel = experiment.GetXPixelsNum();
|
||||
size_t ypixel = experiment.GetYPixelsNum();
|
||||
size_t start_x = std::lround(experiment.GetBeamX_pxl());
|
||||
@@ -52,23 +46,30 @@ void NeuralNetResPredictor::PrepareInternal(const T* image) {
|
||||
}
|
||||
}
|
||||
|
||||
void NeuralNetResPredictor::Prepare(const int16_t *image) {
|
||||
PrepareInternal(image);
|
||||
void NeuralNetResPredictor::Prepare(const DiffractionExperiment& experiment, const int16_t *image) {
|
||||
PrepareInternal(experiment, image);
|
||||
}
|
||||
|
||||
void NeuralNetResPredictor::Prepare(const int32_t *image) {
|
||||
PrepareInternal(image);
|
||||
void NeuralNetResPredictor::Prepare(const DiffractionExperiment& experiment, const int32_t *image) {
|
||||
PrepareInternal(experiment, image);
|
||||
}
|
||||
|
||||
size_t NeuralNetResPredictor::GetMaxPoolFactor() const {
|
||||
size_t NeuralNetResPredictor::GetMaxPoolFactor(const DiffractionExperiment& experiment) const {
|
||||
float max_direction = std::max(experiment.GetXPixelsNum(), experiment.GetYPixelsNum()) / 2.0;
|
||||
size_t pool_factor = std::lround(max_direction / 512.0f);
|
||||
if (pool_factor <= 0)
|
||||
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "Detector size is too small");
|
||||
|
||||
if (pool_factor > 8)
|
||||
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "Detector size is too large");
|
||||
return pool_factor;
|
||||
}
|
||||
|
||||
float NeuralNetResPredictor::Inference(const void *image) {
|
||||
float NeuralNetResPredictor::Inference(const DiffractionExperiment& experiment, const void *image) {
|
||||
if (experiment.GetPixelDepth() == 2)
|
||||
Prepare((int16_t *) image);
|
||||
Prepare(experiment, (int16_t *) image);
|
||||
else
|
||||
Prepare((int32_t *) image);
|
||||
Prepare(experiment, (int32_t *) image);
|
||||
|
||||
#ifdef JFJOCH_USE_TORCH
|
||||
auto options = torch::TensorOptions().dtype(at::kFloat);
|
||||
|
||||
Reference in New Issue
Block a user