コードは、変数mean
にnumpyの形式のデータを読み取るためargs.mean_file
変数を利用します。最も簡単な方法は、入力データと同じ寸法を有しmean
と呼ばれる配列を作成し、それをmean_pixel
変数を格納し、単一の平均値を持つargs.mean_pixel
という名前の新しいパーサ引数に持参し、すべてにmean_pixel
値をコピーすることになります配列内の要素残りのコードは正常に機能します。
parser.add_argument(
"--mean_pixel",
type=float,
default=128.0,
help="Enter the mean pixel value to be subtracted."
)
上記のコードセグメントは、mean_pixel
というコマンドライン引数を取ろうとします。
コードセグメントに置き換え:mean_file
が引数として渡されていない場合、これは、引数として渡さmean_pixel
値を選択するためのコードを作成します
if args.mean_file:
mean = np.load(args.mean_file)
elif args.mean_pixel:
mean_pixel = args.mean_pixel
mean = np.array([image_dims[0],image_dims[1],channels]) #where channels is the number of channels of the image
mean.fill(mean_pixel)
:で
if args.mean_file:
mean = np.load(args.mean_file)
を。上記のコードは、画像の次元の配列を作成し、mean_pixel
の値で埋めます。
残りのコードは変更する必要はありません。