Jump to content
Compvision.ru
Sign in to follow this  
OmgZomg

Wrong array shape

Recommended Posts

Всем доброго дня!

Загружаю изображение в обученную модель

from keras.models import load_model
import numpy as np


from keras.preprocessing import image
model = load_model('my_model33-16.h5')


img_path='/home/alexander/s_gray/3_39095_31718.png'
img = image.load_img(img_path)
img_tensor = image.img_to_array(img)                  
img_tensor = np.expand_dims(img_tensor, axis=0)        

 

Выдает ошибку

ValueError: Error when checking input: expected img to have shape (128, 128, 1) but got   array with shape (128, 128, 3)

Изображения уже переведены в grayscale

import os
from PIL import Image
files = os.listdir('/home/alexander/s2/')
for f in files:
    img=Image.open('/home/alexander/s2/'+f)
    gray = img.convert('L')
    im_resized = gray.resize((128, 128))
    im_resized.save('/home/alexander/s_gray/'+f)

Что не так?)

Share this post


Link to post
Share on other sites

Так это, однослойное требует :) 
Проверьте shape загруженного изображения, если слоев 3, просто отцепите один, в сером они все одинаковые.

  • Thanks 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×