さまざまな画像データ タイプの画像パイプラインを実装したいと考えています。パイプラインを記述するメソッド、データ型パラメーターを指定する 、および入力画像を指定するメンバーをGenerator含むクラスを定義しています。の型を上で定義した型に指定すると、ジェネレーターを実行するときにどの型を指定しても、入力画像の型は常に既定の型になります。メソッドの本体内の宣言をコピーすると、正常に動作しているようです。これは、異なるタイプを持つことができる入力画像でパイプラインを定義する正しい方法ですか?build()GeneratorParam<type>ImageParamImageParamGeneratorParam<Type>ImageParambuild()
私が最初に書いたクラスは次のとおりです。
#include "Halide.h"
using namespace Halide;
class myGenerator : public Generator<myGenerator>
{
public:
// Image data type as a parameter of the generator; default: float
GeneratorParam<Type> datatype{"datatype", Float(32)};
// Input image to the pipeline
ImageParam input{datatype, 3, "input"}; // datatype=Float(32) always
// Pipeline
Func build()
{
// ...
}
};
ジェネレーターをコンパイルして実行するとdatatype、デフォルトとは異なるパイプラインが生成されます。
$ ./myGenerator -f pipeline_uint8 -o . datatype=uint8
その後、すべて問題ないように見えますが、パイプラインに渡すバッファーが uint8 であるため、実行時にパイプラインがクラッシュしますが、float 型 (ジェネレーター クラスで指定したデフォルト) のイメージが予期されていました。
Error: Input buffer input has type float32 but elem_size of the buffer passed in is 1 instead of 4
ImageParamブロック内の宣言をコピーして問題を修正しましたbuild()が、それは少し汚いようです。より良い方法はありますか?これが今のクラスです:
#include "Halide.h"
using namespace Halide;
class myGenerator : public Generator<myGenerator>
{
public:
// Image data type as a parameter of the generator; default: float
GeneratorParam<Type> datatype{"datatype", Float(32)};
// Input image to the pipeline
ImageParam input{datatype, 3, "input"};
// Pipeline
Func build()
{
// Copy declaration. This time, it picks up datatype
// as being the type inputted when executing the
// generator instead of using the default.
ImageParam input{datatype, 3, "input"};
// ...
}
};
ありがとう。