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

home2 게시판 Python, SQL 게시판 텐서플로우 ValueError: Data cardinality is ambiguous 에러

텐서플로우 ValueError: Data cardinality is ambiguous 에러

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

    Chagon Son
    참가자

    Model: "sequential_10"
    _________________________________________________________________
    Layer (type) Output Shape Param #
    =================================================================
    conv2d_9 (Conv2D) (None, 28, 28, 32) 320
    _________________________________________________________________
    max_pooling2d_9 (MaxPooling2 (None, 14, 14, 32) 0
    _________________________________________________________________
    flatten_10 (Flatten) (None, 6272) 0
    _________________________________________________________________
    dense_21 (Dense) (None, 64) 401472
    _________________________________________________________________
    dense_22 (Dense) (None, 10) 650
    =================================================================
    Total params: 402,442
    Trainable params: 402,442
    Non-trainable params: 0
    _________________________________________________________________
    AAAAAAAAAAAAAAAAAAAAAAAAAA

    ---------------------------------------------------------------------------

    ValueError Traceback (most recent call last)

    <ipython-input-11-968f22cba899> in <module>()
    46 print("AAAAAAAAAAAAAAAAAAAAAAAAAA")
    47
    ---> 48 model.fit(trainX, trainY, validation_data=(testX, testY), epochs=5)
    49
    50 score = model.evaluate(testX, testY)

    3 frames
    /usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/data_adapter.py in _check_data_cardinality(data)
    1527 label, ", ".join(str(i.shape[0]) for i in nest.flatten(single_data)))
    1528 msg += "Make sure all arrays contain the same number of samples."
    -> 1529 raise ValueError(msg)
    1530
    1531

    ValueError: Data cardinality is ambiguous:
    x sizes: 60000
    y sizes: 10000
    Make sure all arrays contain the same number of samples.

     

    에러발생을 알려주세요.

    참고) COLAB에서 프로그램을 실행하였습니다.

     

    프로그램 원본입니다.

    import tensorflow as tf
    import matplotlib.pyplot as plt
    import numpy as np

    (trainX, trainY), (testX, testY) = tf.keras.datasets.fashion_mnist.load_data()

    trainX = trainX / 255.0
    trainY = trainY / 255.0

    trainX = trainX.reshape ( (trainX.shape[0], 28, 28, 1))
    trainY = testX.reshape ( (testX.shape[0], 28, 28, 1))

    class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat', 'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot']

    #print(trainX[0])
    #print(trainX.shape)

    #print(testX[0])
    #print(testX.shape)

    #print(trainY)

    #plt.imshow(trainX[1])
    #plt.gray()
    #plt.colorbar()
    #plt.show()

    model = tf.keras.Sequential([
                                tf.keras.layers.Conv2D( 32, (3, 3), padding="same", activation="relu", input_shape=(28, 28, 1) ),
                                tf.keras.layers.MaxPooling2D( (2,2) ),
                                # tf.keras.layers.Dense(128, input_shape=(28, 28), activation="relu"),
                                tf.keras.layers.Flatten(),
                                tf.keras.layers.Dense(64, activation="relu"),
                                tf.keras.layers.Dense(10, activation="softmax"),

    ])

    model.summary()

    model.compile(loss="sparse_categorical_crossentropy", optimizer="adam", metrics=['accuracy'])

    print("AAAAAAAAAAAAAAAAAAAAAAAAAA")

    model.fit(trainX, trainY, validation_data=(testX, testY), epochs=5)

    score = model.evaluate(testX, testY)

    #6865

    codingapple
    키 마스터

    x데이터가 60000개 들어왔는데 y데이터는 왜 1만개밖에 없냐는 에러 같습니다 

    trainX = trainX.reshape ( (trainX.shape[0], 28, 28, 1))
    trainX = testX.reshape ( (testX.shape[0], 28, 28, 1))

    이렇게 바꾸면 될듯합니다 

    #6875

    Chagon Son
    참가자

    감사합니다.  프로그램이 잘 돌아가네요.

3 글 보임 - 1 에서 3 까지 (총 3 중에서)
  • 답변은 로그인 후 가능합니다.

About

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

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

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