4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

DCGAN×MNIST:学習データ量の違いで生成画像はどう変わる?Lossと質の限界をチェック!

Last updated at Posted at 2025-09-02

はじめに

GMOコネクトの永田です。

前回の記事でDCGAN(Deep Convolutional Generative Adversarial Networks)を試しているとき、学習に利用するデータ量がどの程度結果に影響するんだろう?と、ふと疑問に思ったので試してみました。

まとめ

  • データ量は、生成される画像の質やlossの収束に強く影響する
  • MNIST(28x28x1)のデータの場合、40,000件ぐらいは必要そうで、それを下回ると結果が劣化する

測定用の改造

前回と同じくTensorflowのチュートリアルを使います。

チュートリアルではデータセットがMNISTの60,000件ですので、微修正します。

def main():
    """Main function to run the DCGAN training."""
    print("TensorFlow version:", tf.__version__)
    
    # Load and prepare the dataset
    (train_images, train_labels), (_, _) = tf.keras.datasets.mnist.load_data()
    
    train_images = train_images.reshape(train_images.shape[0], 28, 28, 1).astype('float32')
    train_images = (train_images - 127.5) / 127.5  # Normalize the images to [-1, 1]
    
    BUFFER_SIZE = 60000
    BATCH_SIZE = 256

    # Batch and shuffle the data
    train_dataset = tf.data.Dataset.from_tensor_slices(train_images).shuffle(BUFFER_SIZE).batch(BATCH_SIZE)

    # pickup 10000 datas for debug <--ここを追加、10,000〜60,000まで手動で変更しながら測定
    train_dataset = train_dataset.take(10000 * BATCH_SIZE // BUFFER_SIZE)

    # Create the models
    以下略

実測データ

比較結果をみてもらう方が、直感的にわかりやすいです。

datasets generated iamge loss
10,000 data_10k_animation.gif combined_loss_history.png
20,000 data_20k_animation.gif combined_loss_history.png
30,000 data_30k_animation.gif combined_loss_history.png
40,000 data_40k_animation.gif combined_loss_history.png
50,000 data_50k_animation.gif combined_loss_history.png
60,000 data_60k_animation.gif combined_loss_history.png

MNIST 30,000データぐらいから生成画像が安定し始めて、40,000データぐらいだと60,000(MNIST最大データ数)と比べても見劣りしない気がします。
20,000データだと生成画像もEpoch進んでも、ブレブレですね。

データ数が学習時間に直結する(正比例する)のでローカルでdebugするときはなるべくデータ数を抑えたいところですが、40,000ぐらいがバランスが良さそうでしょうか。

なお、Epoch毎のPNGをEpoch数をいれながらアニメーションGIFには、Copilot Agent Claude Sonnet4が以下のような雑なpromptでも一発でやってくれました😊

tesorflow_tutorials_dcgan のimage_at_epochのPNGを、1つのアニメーション画像にしたい。また、Epoch数もそのアニメーション内に表示したい。

(再掲)まとめ

  • データ量は、生成される画像の質やlossの収束に強く影響する
  • MNIST(28x28x1)のデータの場合、40,000件ぐらいは必要そうで、それを下回ると結果が劣化する

弊社では、機械学習・AI・LLMなどを使ったサービスの開発や技術支援をはじめ、幅広い支援を行っておりますので、何かありましたらお気軽にお問合せください。

お問合せ: https://gmo-connect.jp/contactus/

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?