Example #1
0
    def runModel(self):
        self.text = ""
        letters, _ = get_letters(get_processed_image(self.image))
        for letter in letters:

            self.text += get_char(self.model.predict(letter).argmax())
        print(self.text)
def predict(image_path, model, top_k, category_names, dev=False):
    if dev:
        print(image_path, model, top_k, category_names, dev)

    image = get_processed_image(image_path)

    model = load_model(model)

    class_names = get_class_names(category_names)

    prediction = model.predict(np.expand_dims(image, axis=0))

    values, indices = tf.math.top_k(prediction, top_k)
    values = values.numpy()[0]

    classes = [class_names[str(value+1)] for value in indices.cpu().numpy()[0]]
    
    if dev:
        print("model.summary")
        print(model.summary())

    print(f'top class: {classes[0]} with % {values[0]*100}')
    print(f'values: {values}\nclasses: {classes}')

    return values, classes
 def save(self, name, content, save=True):
     if self and not self._committed and None in self.patterns:
         # Apply original image process
         img = self._get_image()
         processed = get_processed_image(self, img, self.patterns[None])
         file_fmt = get_fileformat_from_filename(name)
         content = get_content_file(processed, file_fmt)
     super(ThumbnailFieldFile, self).save(name, content, save=save)
 def _create_thumbnail(self, patterns):
     """create PIL thumbnail of this field file
     
     Attribute:
         patterns -- A process patterns to generate thumbnail
     """
     img = self._get_image()
     thumb = get_processed_image(self, img, patterns)
     return thumb