• 로그인
  • 장바구니에 상품이 없습니다.

home2 게시판 Python, SQL 게시판 tensorflow.keras.utils 모델을 그림으로 미리보기

tensorflow.keras.utils 모델을 그림으로 미리보기

2 글 보임 - 1 에서 2 까지 (총 2 중에서)
  • 글쓴이
  • #77021

    조승엽
    참가자
    import tensorflow as tf 
    import numpy as np
    import matplotlib.pyplot as plt
    (trainX, trainY), (testX, testY) = tf.keras.datasets.fashion_mnist.load_data()
    trainX = trainX / 255.0
    testX = testX / 255.0
    trainX = trainX.reshape( (trainX.shape[0], 28,28,1) )
    testX = testX.reshape( (testX.shape[0], 28,28,1) )
    # 중간에 레이어를 두개 합치기 섞고 비비고 할수있는 방법이 있음 - Functional API쓰면 가능
    # 기존에 썻던 Sequential 은 차례대로 하는것 밖에 안됨
    model = tf.keras.Sequential([
        tf.keras.layers.Flatten(),
        tf.keras.layers.Dense(128, activation='relu'),
        tf.keras.layers.Dense(10, activation='softmax'),
    ])
    model.compile(loss='sparse_categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
    # model.fit(trainX, trainY, validation_data=(testX, testY), epochs=3)
    from tensorflow.keras.utils import plot_model
    plot_model(model, to_file='model.png', show_shapes=True, show_layer_names=True) # 모델을 그림으로 미리보기 가능
    
    
    이거 에러나네요.  colab환경에서 하고있는데 아래처럼 뜨네요.
    
    
    ValueError                                Traceback (most recent call last)
    <ipython-input-8-8a648e7c2536> in <cell line: 29>()
         27 from tensorflow.keras.utils import plot_model
         28 
    ---> 29 plot_model(model, to_file='model.png', show_shapes=True, show_layer_names=True) # 모델을 그림으로 미리보기 가능
    /usr/local/lib/python3.9/dist-packages/keras/utils/vis_utils.py in plot_model(model, to_file, show_shapes, show_dtype, show_layer_names, rankdir, expand_nested, dpi, layer_range, show_layer_activations, show_trainable)
        443 
        444     if not model.built:
    --> 445         raise ValueError(
        446             "This model has not yet been built. "
        447             "Build the model first by calling `build()` or by calling "
    ValueError: This model has not yet been built. Build the model first by calling `build()` or by calling the model on a batch of data.
    #77073

    codingapple
    키 마스터
    model.fit 하고 나서 출력해보거나 
    input_shape=(28,28,1)
    model.build(input_shape)  
    같은거 실행하고 나서 해봅시다
2 글 보임 - 1 에서 2 까지 (총 2 중에서)
  • 답변은 로그인 후 가능합니다.

About

현재 월 700명 신규수강중입니다.

  (09:00~20:00) 빠른 상담은 카톡 플러스친구 코딩애플 (링크)
  admin@codingapple.com
  이용약관
ⓒ Codingapple, 강의 예제, 영상 복제 금지
top

© Codingapple, All rights reserved. 슈퍼로켓 에듀케이션 / 서울특별시 강동구 고덕로 19길 30 / 사업자등록번호 : 212-26-14752 온라인 교육학원업 / 통신판매업신고번호 : 제 2017-서울강동-0002 호 / 개인정보관리자 : 박종흠