2

SPP net is used for variable size input images. SPP Net implementation in keras in here uses two model.fit for two sizes of images. I have 278 images of all different sizes, so how to use model.fit in this case? and how keras calculating efficiency and other performance parameter after two model.fit uses? I am quoting some lines from spp paper where author write that

For a single network to accept variable input sizes, we approximate it by multiple networks that share all parameters, while each of these networks is trained using a fixed input size. In each epoch we train the network with a given input size, and switch to another input size for the next epoch. Experiments show that this multi-size training converges just as the traditional single-size training,and leads to better testing accuracy.

Should we have to use as many epoch as we have no. of variable size images?

Hitesh
  • 1,285
  • 6
  • 20
  • 36

1 Answers1

0

You can try generator (see stanford.edu).


If all images are different sizes, then the batch size should be 1. Pay attention to the X and y shapes.

class WordImageGeneratorSPP(object):
    def __init__(self, shuffle=True):
        self.shuffle = shuffle

    def generate(self, items):
        while 1:
            if self.shuffle:
                random.shuffle(items)
            for item in items:
                X = item[0]
                y = item[1]
                yield X, y

train_gen = WordImageGeneratorSPP().generate(train_data)
model.fit_generator(generator=train_gen, ...)

You can plot the generator output, but you should also pay attention to the X and y shapes.

import matplotlib.pyplot as plt

train_gen = WordImageGeneratorSPP().generate(train_data)

for X, y in train_gen:
    plt.imshow(X)
    plt.title(y)
    plt.show()