0
$\begingroup$

I am getting this error : ValueError: Failed to find data adapter that can handle input' I even changed the list to arrays but still the error keeps pooping up. enter image description here

This is the code:

import tensorflow.keras as keras
"""training the model starting with a random noise"""
sigma=1/30
z = make_noise("random", 32, (w, h))
losses1 = []
ms1=[]
psnr1=[]
losses = numpy.array(losses1)
ms = numpy.array(ms1)
psnr=numpy.array(psnr1)
for i in range(100):
    loss = model.fit(add_noise(z, sigma), img)
    losses.append(loss)
    y = model.predict_on_batch(z)
    m=PSNR(img1,y*255)
    print(m)
    psnr.append(m)
    if i % 20 == 0:
        y = model.predict_on_batch(z)
        image=postprocess(y[0])
        ms.append(image)
        plt.imshow(image)
        plt.show()

make_noise & add_noise functions:

"""Creating functions for necessary preprocessing and post processing"""
def preprocess(img):
    img = img_to_array(img)
    img = np.expand_dims(img, axis=0)
    img = img.astype('float32')
    img = img / 255
    return img


def postprocess(img):
    """Convert numpy array to image"""
    if len(img.shape) == 2:
        img = np.expand_dims(img, axis=-1)
    img = array_to_img(img)
    return img


def crop_image(img, d=32):
#     '''Make dimensions divisible by `d`'''

    new_size = (img.size[0] - img.size[0] % d,
                 img.size[1] - img.size[1] % d)

    bbox = [
         int((img.size[0] - new_size[0]) / 2),
         int((img.size[1] - new_size[1]) / 2),
         int((img.size[0] + new_size[0]) / 2),
         int((img.size[1] + new_size[1]) / 2),
     ]

    img_cropped = img.crop(bbox)
    return img_cropped


def get_noisy_image(img, sigma):
    """Adds Gaussian noise to an image."""
    img_noisy = np.clip(img + np.random.normal(scale=sigma, size=img.shape), 0, 1).astype(np.float32)
    return img_noisy


def make_noise(method, channel, sizes):
    """Creating a random image of range points"""
    if method == 'random':
        shape = (1, sizes[0], sizes[1], channel)
        noise = np.random.uniform(0, 0.1, size=shape)
    return noise


def add_noise(x, sigma):
    noise = np.random.normal(0, sigma, size=x.shape)
    return x + noise

```
$\endgroup$
2
  • $\begingroup$ What do your make_noise and add_noise functions look like? $\endgroup$
    – Oxbowerce
    Jan 31 at 18:39
  • $\begingroup$ I have added those functions to the Question if u could check n let me know @Oxbowerce $\endgroup$ Feb 1 at 14:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.