cropped - みる会図書館


検索対象: TensorFlowはじめました 2
6件見つかりました。

1. TensorFlowはじめました 2

tr_images ground_truths for i in range(batch—size) : tf. random—crop( cropped—image image, (input—size, input—size, channels)) tf. image. resize_images( ground—truth cropped_image, (output—size' output—size)) tf. image. resize_images( resized image cropped—image' (input—size / / scale' input—size / / scate) , method=tf. image. ResizeMeth0d. BICUBIC) tf. image. resize_images( tr—image resized image, (input—size, input—size) , method=tf. image. ResizeMethod . BICUBIC) ground—truths. append(ground—truth) tr—images ・ append(lr—image) tf. stack(lr—images, axis=@) lr_images tf. stack(ground—truths, axis=@) ground_truths return tr_images / 255 , ground—truths / 255 ランダムで切り出した 33px の画像 (cropped-image) を縮小して高解像度の画像 「 ground-truth 」とします。また、 cropped-image を縮小してから、もう一度拡大する ことで、画像を低解像度の画像「 tr-image 」を作成しています。 48 第 3 章超解像奮闘記

2. TensorFlowはじめました 2

cropped—image, (output_size, output_size) ) resized_image = tf. image. resize_nmages( cropped—image, (input—size / / scale, input_size / / scate) , method=tf. image . ResizeMethod . BICUBIC) lr—image tf. image. resize_images( resized_image, (input—size, input_size) , method=tf. image. ResizeMethod . BICUBIC) ground—truths. append(ground_truth) lr—images ・ append(lr—image) lr_images tf. stack(lr_images, axis=@) ground_truths tf. stack(ground—truths, axis=@) return lr_images / 255 , ground_truths / 255 ます、読み込んだファイルを tf. image. decode ー jpeg でデコードします 次に、指定したサイズでランダムで切り抜き (tf. random_crop) 、画像 cropped_image を指定のサイズ (output_size) に縮小します。これが ground_truth 、モデルの出力とし て期待する高解像度の画像となります。 また、 cropped-image を元に、解像度の低い画像 (tr_image) を作ります。一度 scale に指定された大きさに縮小 (resize) したあと、再び拡大することで擬似的に解像度を下げ ☆☆☆ 1 1 x 1 1 33X33 cropped—image 図関数 load_image の動作 ます。 CNN 33X33 lr—image ground—truth 21X21 第 2 章 CNN で超解像 27

3. TensorFlowはじめました 2

filename—queue = tf. train. string_input_producer(file tist, shuffte=True) tf. WhoteFileReader() reader value reader. read(filename_queue) tf. image. decode—jpeg(value, channels=channels) 1 mage lr_images ground_truths for i in range(batch—size) : tf. random—crop( cropped—image image, (input—size, input—size, channets)) lr_image = tf. image . resize—images( cropped—image' (input—size / / scate, input_size / / scate) , method=tf. image . ResizeMethod . BICUBIC) lr_image = tf. image . resize_images( lr_image, (input—size, input_size) , method=tf. image . ResizeMeth0d . BICUBIC) offset_teft (input_size ー output_size) / / 2 offset_top (input_size output—size) / / 2 ground—truth tf. image. crop—to—bounding—box( cropped—image, offset—top, offset—left, output—size, output_size) lr—images ・ append(lr—image) ground—truths . append(ground—truth) tf. stack(lr_images, axis=@) images tf. stack(ground—truths, axis=@) ground_truths return tr_images / 255 , ground_truths / 255 また、 evat. py でプロックに分割するときのスライド幅 (stride) を、 MODEL. INPUT_SIZE から MODEL. OUTPUT_SIZE に変更します ( リスト 3.6 ) 。 50 第 3 章超解像奮闘記

4. TensorFlowはじめました 2

図 3.9 image 」 oader_svs. py の動作 33X33 cropped—image lr—image 33X33 1 1 x 1 1 0 → 0 CNN ground—truth 21X21 これまで見てきたように、超解像を実現するには周辺部の特徴を取り込む必要があります。 しかし、畳み込み層でパディングを設定してもプロックの境目にノイズが発生します。 そこで、学習時にパディングの領域を含めて読み込むように変更します。 conv2d で 0 パディングを追加するのでなく、失われるピクセル分、大きめに画像を読み込み ます ( 図 3.10 ) 。 図 3.10 変更後の動作 cropped—image 33X33 lr—image 33X33 ☆☆☆ CNN ground—truth 21X21 リスト 3.5 は、変更後のプログラムです。 リスト 3.5 : srcnn/image 」 oader_vvv. py def toad_image(file_list, input_size, output_size, scaIe=2, batch_size=l) : with tf. name_scope( 'image_loader vvv' ) : channels=l, 第 3 章超解像奮闘記 49

5. TensorFlowはじめました 2

MODEL . CHANNELS) for row -in range(v_num) : for C01 in range(h_num) : left C01 ☆ stride[INDEX_HORIZONTAL] row ☆ stride[INDEX_VERT 工 CAL] top right left + MODEL . 工 NPUT SIZE bottom = top + MODEL. 工 NPUT_SIZE mode 'L' if MODEL . CHANNELS cropped—image image ・ crop( (teft, top, right, bottom)) . convert(mode) btocks[row] [ C01 ] np ・ array(cropped—image. getdata()) \ . reshape(shape) / 255 1 else ' RGB' return blocks 超解像処理 リスト 2.10 の関数ーー process は、 train ー dir に保存されている学習済みモデルのパラメー ターを使って、各プロックに超解像処理をします。 リスト 2.10 : srcnn/eval.py def __process(blocks, train-dir) : tf. ptaceholder(tf. fIoat32, image—placeholder shape=None) 1 mage logits S a V e r config tf. expand—dims(image—ptaceholder, @) MODEL. inference(image) tf. train . Saver(tf. gtobal—variables()) tf. ConfigProto( atIow_soft_pIacement=True, Iog—device—pIacement=Fa1se) with tf. Session(config=config) as sess: saver . restore(sess, checkpoint. model checkpoint—path) checkpoint = tf. train . get—checkpoint_state(train—dir) V num h num ten(btocks) ten(btocks[@] ) 第 2 章 CNN で超解像 35

6. TensorFlowはじめました 2

1 . 学習データの読み込み 2 . 誤差関数の定義 3 . 最適化アルゴリズムの設定 4 . 学習の実行 # coding: UTF-8 リスト 2.3 : srcnn/image 」 oader_svs. py 像度の画像 (ground-truths) の組み合わせです。 戻り値は、 batch ー size で指定した数の学習に使う低解像度の画像 (tr-images) と、高解 ズ (input-size) 、モデルが出力する画像サイズ (output-size) を指定します。 引数に読み込む画像ファイルのリスト (jpeg-file-list) と、モデルへ入力する画像サイ リスト 2.3 の関数 load ー image は、画像の読み込み処理です。 学習データの読み込み from from from future future_ future_ import absolute_import import division import print—function import tensorflow as tf def load_image(file—list, input—size' output—size' channets=l' scaIe=2, batch—size=l) : with tf. name_scope( 'image—loader—svs' ) : 26 tf. train. string—input—producer(fite—list, filename_queue shuffte=True) reader = tf. Wh01eFiteReader() reader. read(filename—queue) value tf. image ・ decode—jpeg(value, channets=channets) nmage lr_images ground_truths for i in range(batch—size) : cropped—image = tf. random—crop( image, (input—size, input—size' channets)) tf. image . resize_images( ground—truth 第 2 章 CNN で超解像