In [1]:
import numpy as np
import re
from IPython.display import display, Math, Latex, Image
In [2]:
import numpy as np
imgs = np.load('pred_imgs.npy')
preds = np.load('pred_latex.npy')
properties = np.load('properties.npy').tolist()
displayPreds = lambda Y: display(Math(Y.split('#END')[0]))
idx_to_chars = lambda Y: ' '.join(map(lambda x: properties['idx_to_char'][x],Y))
#displayIdxs = lambda Y: display(Math(''.join(map(lambda x: properties['idx_to_char'][x],Y))))
In [3]:
import PIL.Image
from cStringIO import StringIO
import IPython.display
import numpy as np
def showarray(a, fmt='png'):
    a = np.uint8(a)
    f = StringIO()
    PIL.Image.fromarray(a).save(f, fmt)
    IPython.display.display(IPython.display.Image(data=f.getvalue()))
In [5]:
batch_size=16
from PIL import Image as Img
for i in xrange(batch_size):
    preds_chars = idx_to_chars(preds[i,1:]).replace('$','')
    print "Original (Input) Image: %d"%(i+1)
    showarray(imgs[i][0])
    print "Predicted Latex"
    print preds_chars.split('#END')[0]
    print "\nRendering the predicted latex"
    displayPreds(preds_chars)
    print "\n"
Original (Input) Image: 1
Predicted Latex
\tilde { q } \equiv \sqrt { \frac { \omega } { g } } \bar { q } , 

Rendering the predicted latex
$$\tilde { q } \equiv \sqrt { \frac { \omega } { g } } \bar { q } , $$

Original (Input) Image: 2
Predicted Latex
\partial _ { \beta } ( \partial _ { \alpha } ~ q _ { a } ~ \dot { x } _ { \alpha } ) ~ \dot { x } _ { \beta } 

Rendering the predicted latex
$$\partial _ { \beta } ( \partial _ { \alpha } ~ q _ { a } ~ \dot { x } _ { \alpha } ) ~ \dot { x } _ { \beta } $$

Original (Input) Image: 3
Predicted Latex
\Theta = \operatorname { l o g } \frac { 4 N } { { \cal M } L } 

Rendering the predicted latex
$$\Theta = \operatorname { l o g } \frac { 4 N } { { \cal M } L } $$

Original (Input) Image: 4
Predicted Latex
\Lambda = e + \theta \sqrt { e } \, \chi . 

Rendering the predicted latex
$$\Lambda = e + \theta \sqrt { e } \, \chi . $$

Original (Input) Image: 5
Predicted Latex
\Omega = \left( \begin{array} { c c } { 0 } & { \ I } \\ { \Gamma } & { 0 } \\ \end{array} \right) . 

Rendering the predicted latex
$$\Omega = \left( \begin{array} { c c } { 0 } & { \ I } \\ { \Gamma } & { 0 } \\ \end{array} \right) . $$

Original (Input) Image: 6
Predicted Latex
\zeta = \frac { 1 } { 2 } + i \frac { \sqrt { \beta } } { 2 } p 

Rendering the predicted latex
$$\zeta = \frac { 1 } { 2 } + i \frac { \sqrt { \beta } } { 2 } p $$

Original (Input) Image: 7
Predicted Latex
\beta = \frac { 3 } { \pi | { \cal D } - 2 5 | } 

Rendering the predicted latex
$$\beta = \frac { 3 } { \pi | { \cal D } - 2 5 | } $$

Original (Input) Image: 8
Predicted Latex
\operatorname { t a n } \frac { \theta } { 2 } = \frac { \beta } { \alpha } \ . 

Rendering the predicted latex
$$\operatorname { t a n } \frac { \theta } { 2 } = \frac { \beta } { \alpha } \ . $$

Original (Input) Image: 9
Predicted Latex
\frac { g _ { S N M } ^ { 2 } \Sigma _ { i } ^ { 2 } } { \Sigma _ { 1 } \Sigma _ { 2 } \Sigma _ { 3 } \Sigma _ { 4 } } . 

Rendering the predicted latex
$$\frac { g _ { S N M } ^ { 2 } \Sigma _ { i } ^ { 2 } } { \Sigma _ { 1 } \Sigma _ { 2 } \Sigma _ { 3 } \Sigma _ { 4 } } . $$

Original (Input) Image: 10
Predicted Latex
\zeta = \frac { 1 } { 2 } + i \frac { \sqrt { \beta } } { 2 } p 

Rendering the predicted latex
$$\zeta = \frac { 1 } { 2 } + i \frac { \sqrt { \beta } } { 2 } p $$

Original (Input) Image: 11
Predicted Latex
e B ^ { * } = \frac { e ^ { 2 } | m | } { 4 \pi } \; . 

Rendering the predicted latex
$$e B ^ { * } = \frac { e ^ { 2 } | m | } { 4 \pi } \; . $$

Original (Input) Image: 12
Predicted Latex
{ C _ { ~ \beta } ^ { \alpha } } = \pm { C } { O } _ { \; \; \beta } ^ { \alpha } 

Rendering the predicted latex
$${ C _ { ~ \beta } ^ { \alpha } } = \pm { C } { O } _ { \; \; \beta } ^ { \alpha } $$

Original (Input) Image: 13
Predicted Latex
h _ { i } ^ { 2 } = h ^ { 2 } \equiv \frac { 2 } { r } , 

Rendering the predicted latex
$$h _ { i } ^ { 2 } = h ^ { 2 } \equiv \frac { 2 } { r } , $$

Original (Input) Image: 14
Predicted Latex
\langle \widetilde { \Theta } ( x ) \ \widetilde { \Theta } ( y ) \; \widetilde { \Theta } 

Rendering the predicted latex
$$\langle \widetilde { \Theta } ( x ) \ \widetilde { \Theta } ( y ) \; \widetilde { \Theta } $$

Original (Input) Image: 15
Predicted Latex
G _ { \mu \nu } ^ { ( a ) } \equiv e ^ { a \phi } g _ { \mu \nu } 

Rendering the predicted latex
$$G _ { \mu \nu } ^ { ( a ) } \equiv e ^ { a \phi } g _ { \mu \nu } $$

Original (Input) Image: 16
Predicted Latex
K = \left( \begin{array} { c c } { \alpha } & { \beta } \\ { \gamma } & { \delta } \\ \end{array} \right) 

Rendering the predicted latex
$$K = \left( \begin{array} { c c } { \alpha } & { \beta } \\ { \gamma } & { \delta } \\ \end{array} \right) $$

In [ ]: