koshian2 / MosaicDeeplearningBook

モザイク除去から学ぶ 最先端のディープラーニング 質問用
18 stars 0 forks source link

Chap8-3.ipynbのTF2.6.0コード修正ポイント #12

Open umi-tyaahan opened 3 years ago

umi-tyaahan commented 3 years ago

tensorflow 2.6.0で動かす場合、いくつか修正するとうまく動作しました。(10epochクリア / 88分) 参考に修正ポイントを記載します。

修正ポイント

TPUの初期化をする

# strategy = tf.distribute.experimental.TPUStrategy(tpu_cluster_resolver) # deprecated
strategy = tf.distribute.TPUStrategy(tpu_cluster_resolver) 

メイン処理部分

インポート修正

utils_tf20 -> utils

from utils import Reduction, distributed, make_grid, make_citation
import utils as utils

load_dataset

batch() にdrop_remainder=Trueを設定

    trainset = tf.data.Dataset.from_tensor_slices(trains).map(
        lambda *args: [preprocess(a) for a in args]
    ).shuffle(128).batch(batch_size,drop_remainder=True).prefetch(buffer_size=tf.data.experimental.AUTOTUNE)    
    val = np.load("test.npz", allow_pickle=True)
    valset = tf.data.Dataset.from_tensor_slices((val["image"], val["mosaic"], val["mask"]))
    valset = valset.map(
        lambda *args: [preprocess(a) for a in args]
    ).batch(batch_size,drop_remainder=True).prefetch(buffer_size=tf.data.experimental.AUTOTUNE) 
koshian2 commented 3 years ago

@umi-tyaahan TF2.6対応ありがとうございました! 素晴らしいです。 Chap8-3のColabにTF2.6対応版のNotebookのリンクを貼っておきました。