Home > Software design >  module 'keras.layers' has no attribute 'experimental'
module 'keras.layers' has no attribute 'experimental'

Time:12-14

hello so I was trying to resize and rescale my dataset as shown below l but I encountered this error:

AttributeError: module 'keras.layers' has no attribute 'experimental'


resize_and_rescale= tf.keras.Sequential([
    layers.experimental.preprocessing.Resizing(IMAGE_SIZE,IMAGE_SIZE),
    layers.experimental.preprocessing.Rescaling(1.0/255)
])

CodePudding user response:

It is different from the Sequential and Sequential model but the current versions is not in the experiments set as same as many of the decoders.

Sample: Implement Sequential and target resizes layer.

import tensorflow as tf

import matplotlib.pyplot as plt

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
: Variables
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
IMAGE_SIZE = ( 21, 16 ) 
IMAGE_WIDTH = 21
IMAGE_HEIGHT = 16
BATCH_SIZE = 1

file = "F:\\Pictures\\actor-Ploy\\274173564_499586534867164_4792476364355345404_n.jpg"

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
: Sequential
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
resize_and_rescale= tf.keras.Sequential([
    tf.keras.layers.Resizing(IMAGE_SIZE[0], IMAGE_SIZE[1]),
    tf.keras.layers.Rescaling(1.0/255)
])

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
: Read image
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
image = tf.io.read_file( file )
image = tf.io.decode_image( image )

image_resize = resize_and_rescale(image)


plt.figure(figsize=(1,2))
plt.title("Sequentail")

plt.subplot(1, 2, 1)
plt.xticks([])
plt.yticks([])
plt.grid(False)
plt.imshow(image)
plt.xlabel("Original")

plt.subplot(1, 2, 2)
plt.xticks([])
plt.yticks([])
plt.grid(False)
plt.imshow(image_resize)
plt.xlabel("Image Resize")

plt.show()

Output: Input to output as effects Sample

CodePudding user response:

actually I tried adding "tf.keras" in front of my layers line and it worked :

resize_and_rescale= tf.keras.Sequential([
tf.keras.layers.experimental.preprocessing.Resizing(IMAGE_SIZE,IMAGE_SIZE),
tf.keras.layers.experimental.preprocessing.Rescaling(1.0/255)])

thank you !

  • Related