最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

conv neural network - I am facing an issue in 'input shape' when I am trying do data augmentation - Stack Overfl

programmeradmin1浏览0评论
dataset_path = "/content/PetImages"
dataset = tf.keras.utils.image_dataset_from_directory(
    dataset_path,
    batch_size=32,
    image_size=(224, 224),  # Resize images
    shuffle=True
)

# Defining Albumentations Transform
transform = A.Compose([
    A.HorizontalFlip(p=0.5),
    A.RandomBrightnessContrast(p=0.2),
    A.Rotate(limit=30, p=0.5),
    A.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)),  # Normalization
])

# Function to apply augmentation
def augment_image(image, label):
    img = image.numpy().astype(np.uint8)  # Convert Tensor to NumPy
    augmented = transform(image=img)["image"]
    return augmented.astype(np.float32), label  # Ensure float dtype

# Wrapping augmentation function for TF dataset
def tf_augment(image, label):
    img, lbl = tf.numpy_function(func=augment_image, inp=[image, label], Tout=[tf.float32, tf.int32])
    img.set_shape((224, 224, 3))
    return img, lbl

# Applying augmentation
augmented_dataset = dataset.map(tf_augment, num_parallel_calls=tf.data.AUTOTUNE)
augmented_dataset = augmented_dataset.batch(32).prefetch(tf.data.AUTOTUNE)

This is the input layer:

model.add(Conv2D(32, kernel_size=(3,3), padding='valid', activation='relu', input_shape=(224, 224, 3)))

And this is the error:

ValueError: Cannot take the length of shape with unknown rank.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论