로그인 바로가기 하위 메뉴 바로가기 본문 바로가기
난이도
기본

텐서플로우로 시작하는 딥러닝 기초

임시 이미지 Deep Learning Zero To All
http://www.boostcourse.org/ai212/forum/13956
좋아요 1216 수강생 15011
train_dataset = train_dataset.map(load_image_train, num_parallel_calls=16)
train_dataset = train_dataset.batch(batch_size)
train_dataset = train_dataset.repeat()
ValueError                                Traceback (most recent call last)
<ipython-input-134-29e472913867> in <module>()
----> 1 train_dataset = train_dataset.map(load_image_train)
      2 train_dataset = train_dataset.batch(batch_size)
      3 train_dataset = train_dataset.repeat()

10 frames
/usr/local/lib/python3.6/dist-packages/tensorflow/python/autograph/impl/api.py in wrapper(*args, **kwargs)
    263       except Exception as e:  # pylint:disable=broad-except
    264         if hasattr(e, 'ag_error_metadata'):
--> 265           raise e.ag_error_metadata.to_exception(e)
    266         else:
    267           raise

ValueError: in user code:

    <ipython-input-72-54caf0320a72>:5 load_image_train  *
        input_image = random_jitter(image_file)
    <ipython-input-38-6abe6ca27c7a>:6 random_jitter  *
        input_image = resize(input_image,176,176)
    <ipython-input-13-c798457c4038>:5 resize  *
        input_image = tf.image.resize(input_image, size=(height,width))
    /usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/image_ops_impl.py:1517 resize_images_v2  **
        skip_resize_if_same=False)
    /usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/image_ops_impl.py:1193 _resize_images_common
        raise ValueError('\'images\' must have either 3 or 4 dimensions.')

    ValueError: 'images' must have either 3 or 4 dimensions.
train_dataset = train_dataset.map(load_image_train, num_parallel_calls=16) 부분에서 오류가 나네요 이유를모르겠어요ㅜㅜ

위에 작성한 함수들도 올려놓을게요 잘못된 부분이 있으면 알려주세요ㅜㅜ
def load_image_train(image_file, label):

    ## 코드 시작 ##
    input_image, label = load(image_file, label)
    input_image = random_jitter(image_file)
    input_image = normalize(input_image)
    ## 코드 종료 ##

    return input_image, label
def load(image_file, label):
    # 해당경로의 파일을 읽어서 float 타입으로 변환합니다.
    image = tf.io.read_file(image_file)
    image = tf.image.decode_jpeg(image)
    image = tf.cast(image, tf.float32)

    return image, label
def random_jitter(input_image):
    # resize, random_crop, random_rotation, random_flip 함수들을 이용하여 augmentation을 합니다.

    ## 코드 시작 ##
    # resizing to 176 x 176 x 3
    input_image = resize(input_image,176,176)
    # randomly cropping to 150 x 150 x 3
    input_image = random_crop(input_image)
    # randomly rotation
    input_image = random_rotation(input_image)    
    # randomly mirroring
    input_image = tf.image.random_flip_left_right(input_image)
    ## 코드 종료 ##

    return input_image
# normalizing the images to [-1, 1]
def normalize(input_image):
    # 이미지 픽셀값의 범위를 normalize 합니다. [0, 255] -> [-1, 1]

    # 코드 시작
    input_image = input_image/127.5 - 1
    # 코드 종료

    return input_image