Image-OutPainting icon indicating copy to clipboard operation
Image-OutPainting copied to clipboard

i want to change mask,a problem occured

Open zhangbaijin opened this issue 4 years ago • 5 comments

it's my code :

 def mask_width(img):
    image = img.copy()
    height = image.shape[0]
    width = image.shape[1]
    new_width = int(width * MASK_PERCENTAGE)
    mask = np.ones([height, new_width, 3])
    missing_x = img[:, :new_width]
    missing_y = img[:, width - new_width:]
    missing_part = np.concatenate((missing_x, missing_y), axis=1)
    image = image[:, :width - new_width]
    image = image[:, new_width:]
    return image, missing_part
    
def get_masked_images(images):
    mask_images = []
    missing_images = []
    for image in images:
        mask_image, missing_image = mask_width(image)
        mask_images.append(mask_image)
        missing_images.append(missing_image)
    return np.array(mask_images), np.array(missing_images)

def get_demask_images(original_images, generated_images):
    demask_images = []
    for o_image, g_image in zip(original_images, generated_images):
        width = g_image.shape[1] // 2
        x_image = g_image[:, :width]
        y_image = g_image[:, width:]
        o_image = np.concatenate((x_image,o_image, y_image), axis=1)
        demask_images.append(o_image)
    return np.asarray(demask_images)

i also change def dcrm_loss d_input_shape = (int(INPUT_SHAPE[0] * (MASK_PERCENTAGE * 2)), int(INPUT_SHAPE[1] * (MASK_PERCENTAGE * 2)), INPUT_SHAPE[2])

and change def gen_loss g_input_shape = (int(INPUT_SHAPE[0] * (MASK_PERCENTAGE * 2)), int(INPUT_SHAPE[1] * (MASK_PERCENTAGE * 2)), INPUT_SHAPE[2])

and i train: Error when checking input: expected input_2 to have shape (256, 128, 3) but got array with shape (128, 128, 3) ...... thanks for your time!

zhangbaijin avatar Sep 10 '19 13:09 zhangbaijin

All the models (Generator, Discriminator) need an Input Shape of (256, 128, 3). As I can see you are feeding an image shape of (128, 128, 3), make sure your custom data preparation is correct.

bendangnuksung avatar Sep 10 '19 14:09 bendangnuksung

i want to put shape of(128,128,3)into model G and D,how should i change ?------------------ 原始邮件 ------------------ 发件人: "Bendang"[email protected] 发送时间: 2019年9月10日(星期二) 晚上10:22 收件人: "bendangnuksung/Image-OutPainting"[email protected]; 抄送: "zhangbaijin"[email protected];"Author"[email protected]; 主题: Re: [bendangnuksung/Image-OutPainting] i want to change mask,aproblem occured (#11)

All the models (Generator, Discriminator) need an Input Shape of (256, 128, 3). As I can see you are feeding an image shape of (128, 128, 3), make sure your custom data preparation is correct.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

zhangbaijin avatar Sep 10 '19 14:09 zhangbaijin

To train with shape of (128, 128, 3) you need to change values in two files:

  1. prepare_data.py :
    input_shape = (256, 256)
    # to
    input_shape = (128, 128)
  1. outpaint.ipynb :
    INPUT_SHAPE = (256, 256, 3)
    # to
    INPUT_SHAPE = (128, 128, 3) 

After you modified the file you need to prepare the data again for (128,128,3) shape using prepare_data.py then you can start training the model.

bendangnuksung avatar Sep 11 '19 05:09 bendangnuksung

excuse me ,Maybe you don't understand what I mean.What you did before was to expand on both sides. Now I want to make it around . So i changed the code,but Error when checking input: expected input_2 to have shape (256, 128, 3) but got array with shape (128, 128, 3) It's not just a change prepare_data.py and outpaint.ipynb ..

thanks for your time!!

zhangbaijin avatar Sep 11 '19 05:09 zhangbaijin

I don't see any code changes that in those three functions (mask_width(), get_masked_images(), get_demask_images()) you have mention above.

Now I want to make it around

I did not understand this part either. Can you elaborate? I hope you understand why we use input shape of (256, 128, 3) instead of (128,128,3)

bendangnuksung avatar Sep 11 '19 05:09 bendangnuksung