441a33dbcade670c339285c1fa5ba70c885014ea,aocr/model/model.py,Model,visualize_attention,#Model#Any#Any#Any#Any#Any#,437

Before Change


        with open(os.path.join(output_dir, "word.txt"), "w") as fword:
            fword.write(output+"\n")
            fword.write(label)
            with open(filename, "rb") as img_file:
                img = Image.open(img_file)
                w, h = img.size
                mh = 32
                mw = math.floor(1. * w / h * mh)
                img = img.resize(
                        (mw, h),
                        Image.ANTIALIAS)
                img_data = np.asarray(img, dtype=np.uint8)
                for idx in xrange(len(output)):
                    output_filename = os.path.join(output_dir, "image_%d.jpg" % (idx))
                    attention = attentions[idx][:(int(mw/4)-1)]
                    attention_orig = np.zeros(mw)
                    for i in xrange(mw):
                        if i/4-1 > 0 and i/4-1 < len(attention):
                            attention_orig[i] = attention[int(i/4)-1]
                    attention_orig = np.convolve(attention_orig, [0.199547, 0.200226, 0.200454, 0.200226, 0.199547], mode="same")
                    attention_orig = np.maximum(attention_orig, 0.3)
                    attention_out = np.zeros((h, mw))
                    for i in xrange(mw):
                        attention_out[:, i] = attention_orig[i]
                    if len(img_data.shape) == 3:
                        attention_out = attention_out[:, :, np.newaxis]
                    img_out_data = img_data * attention_out
                    img_out = Image.fromarray(img_out_data.astype(np.uint8))
                    img_out.save(output_filename)

    def _prepare_image(self, img):
        image = tf.image.decode_png(img, channels=1)
        dims = tf.shape(image)

After Change


        with open(os.path.join(output_dir, "word.txt"), "w") as fword:
            fword.write(output+"\n")
            fword.write(label)
            file_img_data = BytesIO(img_data)
            img = Image.open(file_img_data)
            w, h = img.size
            mh = 32
            mw = math.floor(1. * w / h * mh)
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 4

Non-data size: 5

Instances


Project Name: emedvedev/attention-ocr
Commit Name: 441a33dbcade670c339285c1fa5ba70c885014ea
Time: 2017-10-26
Author: ckirmse@yahoo.com
File Name: aocr/model/model.py
Class Name: Model
Method Name: visualize_attention


Project Name: emedvedev/attention-ocr
Commit Name: 8d1fa993ddc330d12636be23644b99cb777d8d72
Time: 2017-10-26
Author: ckirmse@yahoo.com
File Name: aocr/model/model.py
Class Name: Model
Method Name: visualize_attention


Project Name: snipsco/snips-nlu
Commit Name: d7ba4f82daac42de28d5a35fcc6379551d9ac905
Time: 2018-11-13
Author: dorian.hoxha@gmail.com
File Name: snips_nlu/pipeline/processing_unit.py
Class Name: ProcessingUnit
Method Name: from_byte_array


Project Name: sony/nnabla
Commit Name: 5aa0e65747cd13c072749cbc7364f61bd149cadf
Time: 2020-03-24
Author: Yuchi.Wen@sony.com
File Name: python/src/nnabla/utils/save.py
Class Name:
Method Name: save