How do I need to configure Keras model to predict an image?












1















The main task is to predict a mask for the input image. So I have the following data for training:




  • lot's of 768x768 original pics like this:


enter image description here




  • and output mask pics(also 768x768) like this:


enter image description here



Also I have validation original pics.



I prepare some kind of neural model that should predict the output mask. I prepared keras model configuaration that should have a topology which looks like below:



enter image description here



The code I prepared for training is there.



import keras
epochs=100

image_datagen = keras.preprocessing.image.ImageDataGenerator()
mask_datagen = keras.preprocessing.image.ImageDataGenerator()
seed = 1
image_generator = image_datagen.flow_from_directory(
'H:/LABS/ship_detection/test_train/',
color_mode='rgb',batch_size=32,target_size=(768,768),
seed=seed)

mask_generator = mask_datagen.flow_from_directory(
'H:/LABS/ship_detection/test_mask/',
class_mode="categorical",batch_size=32,target_size=(768,768),
seed=seed)

train_generator = zip(image_generator, mask_generator)

model.fit_generator(generator=train_generator,
epochs=epochs,
callbacks=callbacks,steps_per_epoch=1)


But when I try to fit generator for prediction I have an issue:



c:usersharwisterappdatalocalprogramspythonpython36libsite-packageskerasenginetraining_generator.py in fit_generator(model, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
208 batch_size = list(x.values())[0].shape[0]
209 else:
--> 210 batch_size = x.shape[0]
211 batch_logs['batch'] = batch_index
212 batch_logs['size'] = batch_size

AttributeError: 'tuple' object has no attribute 'shape'


I do something wrong for sure, but I can't understand anything from these kind of errors. The simple question I can't find a response in Google is: How can I push into Keras two images (input and output images) for training and after training get an output image providing an input image?










share|improve this question

























  • If the answer resolved your issue, kindly accept it by clicking on the checkmark next to the answer to mark it as "answered" - see What should I do when someone answers my question?

    – today
    Nov 26 '18 at 15:56











  • @today I saw your responce. Currently a have personal issue so, I can't spend some time to check your solution. I'll let you know about results later. Don't worry

    – keipa
    Nov 27 '18 at 9:34
















1















The main task is to predict a mask for the input image. So I have the following data for training:




  • lot's of 768x768 original pics like this:


enter image description here




  • and output mask pics(also 768x768) like this:


enter image description here



Also I have validation original pics.



I prepare some kind of neural model that should predict the output mask. I prepared keras model configuaration that should have a topology which looks like below:



enter image description here



The code I prepared for training is there.



import keras
epochs=100

image_datagen = keras.preprocessing.image.ImageDataGenerator()
mask_datagen = keras.preprocessing.image.ImageDataGenerator()
seed = 1
image_generator = image_datagen.flow_from_directory(
'H:/LABS/ship_detection/test_train/',
color_mode='rgb',batch_size=32,target_size=(768,768),
seed=seed)

mask_generator = mask_datagen.flow_from_directory(
'H:/LABS/ship_detection/test_mask/',
class_mode="categorical",batch_size=32,target_size=(768,768),
seed=seed)

train_generator = zip(image_generator, mask_generator)

model.fit_generator(generator=train_generator,
epochs=epochs,
callbacks=callbacks,steps_per_epoch=1)


But when I try to fit generator for prediction I have an issue:



c:usersharwisterappdatalocalprogramspythonpython36libsite-packageskerasenginetraining_generator.py in fit_generator(model, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
208 batch_size = list(x.values())[0].shape[0]
209 else:
--> 210 batch_size = x.shape[0]
211 batch_logs['batch'] = batch_index
212 batch_logs['size'] = batch_size

AttributeError: 'tuple' object has no attribute 'shape'


I do something wrong for sure, but I can't understand anything from these kind of errors. The simple question I can't find a response in Google is: How can I push into Keras two images (input and output images) for training and after training get an output image providing an input image?










share|improve this question

























  • If the answer resolved your issue, kindly accept it by clicking on the checkmark next to the answer to mark it as "answered" - see What should I do when someone answers my question?

    – today
    Nov 26 '18 at 15:56











  • @today I saw your responce. Currently a have personal issue so, I can't spend some time to check your solution. I'll let you know about results later. Don't worry

    – keipa
    Nov 27 '18 at 9:34














1












1








1


1






The main task is to predict a mask for the input image. So I have the following data for training:




  • lot's of 768x768 original pics like this:


enter image description here




  • and output mask pics(also 768x768) like this:


enter image description here



Also I have validation original pics.



I prepare some kind of neural model that should predict the output mask. I prepared keras model configuaration that should have a topology which looks like below:



enter image description here



The code I prepared for training is there.



import keras
epochs=100

image_datagen = keras.preprocessing.image.ImageDataGenerator()
mask_datagen = keras.preprocessing.image.ImageDataGenerator()
seed = 1
image_generator = image_datagen.flow_from_directory(
'H:/LABS/ship_detection/test_train/',
color_mode='rgb',batch_size=32,target_size=(768,768),
seed=seed)

mask_generator = mask_datagen.flow_from_directory(
'H:/LABS/ship_detection/test_mask/',
class_mode="categorical",batch_size=32,target_size=(768,768),
seed=seed)

train_generator = zip(image_generator, mask_generator)

model.fit_generator(generator=train_generator,
epochs=epochs,
callbacks=callbacks,steps_per_epoch=1)


But when I try to fit generator for prediction I have an issue:



c:usersharwisterappdatalocalprogramspythonpython36libsite-packageskerasenginetraining_generator.py in fit_generator(model, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
208 batch_size = list(x.values())[0].shape[0]
209 else:
--> 210 batch_size = x.shape[0]
211 batch_logs['batch'] = batch_index
212 batch_logs['size'] = batch_size

AttributeError: 'tuple' object has no attribute 'shape'


I do something wrong for sure, but I can't understand anything from these kind of errors. The simple question I can't find a response in Google is: How can I push into Keras two images (input and output images) for training and after training get an output image providing an input image?










share|improve this question
















The main task is to predict a mask for the input image. So I have the following data for training:




  • lot's of 768x768 original pics like this:


enter image description here




  • and output mask pics(also 768x768) like this:


enter image description here



Also I have validation original pics.



I prepare some kind of neural model that should predict the output mask. I prepared keras model configuaration that should have a topology which looks like below:



enter image description here



The code I prepared for training is there.



import keras
epochs=100

image_datagen = keras.preprocessing.image.ImageDataGenerator()
mask_datagen = keras.preprocessing.image.ImageDataGenerator()
seed = 1
image_generator = image_datagen.flow_from_directory(
'H:/LABS/ship_detection/test_train/',
color_mode='rgb',batch_size=32,target_size=(768,768),
seed=seed)

mask_generator = mask_datagen.flow_from_directory(
'H:/LABS/ship_detection/test_mask/',
class_mode="categorical",batch_size=32,target_size=(768,768),
seed=seed)

train_generator = zip(image_generator, mask_generator)

model.fit_generator(generator=train_generator,
epochs=epochs,
callbacks=callbacks,steps_per_epoch=1)


But when I try to fit generator for prediction I have an issue:



c:usersharwisterappdatalocalprogramspythonpython36libsite-packageskerasenginetraining_generator.py in fit_generator(model, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
208 batch_size = list(x.values())[0].shape[0]
209 else:
--> 210 batch_size = x.shape[0]
211 batch_logs['batch'] = batch_index
212 batch_logs['size'] = batch_size

AttributeError: 'tuple' object has no attribute 'shape'


I do something wrong for sure, but I can't understand anything from these kind of errors. The simple question I can't find a response in Google is: How can I push into Keras two images (input and output images) for training and after training get an output image providing an input image?







python machine-learning keras deep-learning image-segmentation






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 7:20









today

11k22037




11k22037










asked Nov 20 '18 at 22:06









keipakeipa

349510




349510













  • If the answer resolved your issue, kindly accept it by clicking on the checkmark next to the answer to mark it as "answered" - see What should I do when someone answers my question?

    – today
    Nov 26 '18 at 15:56











  • @today I saw your responce. Currently a have personal issue so, I can't spend some time to check your solution. I'll let you know about results later. Don't worry

    – keipa
    Nov 27 '18 at 9:34



















  • If the answer resolved your issue, kindly accept it by clicking on the checkmark next to the answer to mark it as "answered" - see What should I do when someone answers my question?

    – today
    Nov 26 '18 at 15:56











  • @today I saw your responce. Currently a have personal issue so, I can't spend some time to check your solution. I'll let you know about results later. Don't worry

    – keipa
    Nov 27 '18 at 9:34

















If the answer resolved your issue, kindly accept it by clicking on the checkmark next to the answer to mark it as "answered" - see What should I do when someone answers my question?

– today
Nov 26 '18 at 15:56





If the answer resolved your issue, kindly accept it by clicking on the checkmark next to the answer to mark it as "answered" - see What should I do when someone answers my question?

– today
Nov 26 '18 at 15:56













@today I saw your responce. Currently a have personal issue so, I can't spend some time to check your solution. I'll let you know about results later. Don't worry

– keipa
Nov 27 '18 at 9:34





@today I saw your responce. Currently a have personal issue so, I can't spend some time to check your solution. I'll let you know about results later. Don't worry

– keipa
Nov 27 '18 at 9:34












1 Answer
1






active

oldest

votes


















0














Since you have separate generators for the images and the labels (i.e. masks), you need to set the class_mode argument to None to prevent the generators from producing any labels arrays:



image_generator = image_datagen.flow_from_directory(class_mode=None, ...)
mask_generator = mask_datagen.flow_from_directory(class_mode=None, ...)


This way, image_generator would only generate the input images and the mask_generator would only generate the mask (i.e. true label) images.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53402303%2fhow-do-i-need-to-configure-keras-model-to-predict-an-image%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Since you have separate generators for the images and the labels (i.e. masks), you need to set the class_mode argument to None to prevent the generators from producing any labels arrays:



    image_generator = image_datagen.flow_from_directory(class_mode=None, ...)
    mask_generator = mask_datagen.flow_from_directory(class_mode=None, ...)


    This way, image_generator would only generate the input images and the mask_generator would only generate the mask (i.e. true label) images.






    share|improve this answer




























      0














      Since you have separate generators for the images and the labels (i.e. masks), you need to set the class_mode argument to None to prevent the generators from producing any labels arrays:



      image_generator = image_datagen.flow_from_directory(class_mode=None, ...)
      mask_generator = mask_datagen.flow_from_directory(class_mode=None, ...)


      This way, image_generator would only generate the input images and the mask_generator would only generate the mask (i.e. true label) images.






      share|improve this answer


























        0












        0








        0







        Since you have separate generators for the images and the labels (i.e. masks), you need to set the class_mode argument to None to prevent the generators from producing any labels arrays:



        image_generator = image_datagen.flow_from_directory(class_mode=None, ...)
        mask_generator = mask_datagen.flow_from_directory(class_mode=None, ...)


        This way, image_generator would only generate the input images and the mask_generator would only generate the mask (i.e. true label) images.






        share|improve this answer













        Since you have separate generators for the images and the labels (i.e. masks), you need to set the class_mode argument to None to prevent the generators from producing any labels arrays:



        image_generator = image_datagen.flow_from_directory(class_mode=None, ...)
        mask_generator = mask_datagen.flow_from_directory(class_mode=None, ...)


        This way, image_generator would only generate the input images and the mask_generator would only generate the mask (i.e. true label) images.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 21 '18 at 7:15









        todaytoday

        11k22037




        11k22037
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53402303%2fhow-do-i-need-to-configure-keras-model-to-predict-an-image%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            mysqli_query(): Empty query in /home/lucindabrummitt/public_html/blog/wp-includes/wp-db.php on line 1924

            How to change which sound is reproduced for terminal bell?

            Can I use Tabulator js library in my java Spring + Thymeleaf project?