Visualization#

Summary in table#

We are already pretty familiar with summary(), which prints a table of summary for DocumentArray and its attributes:

from docarray import DocumentArray

da = DocumentArray.empty(3)

da.summary()
        Documents Summary         
                                  
  Length                 3        
  Homogenous Documents   True     
  Common Attributes      ('id',)  
                                  
                     Attributes Summary                     
                                                            
  Attribute   Data type   #Unique values   Has empty value  
 ────────────────────────────────────────────────────────── 
  id          ('str',)    3                False            

Image sprites#

If a DocumentArray contains all image Documents, you can plot all images in one sprite image using plot_image_sprites().

from docarray import DocumentArray

docs = DocumentArray.from_files('*.jpg')
docs.plot_image_sprites()
../../../_images/sprite-image.png

Plot Matches#

If an image Document contains the matching images in its .matches attribute, you can visualise the matching results using plot_matches_sprites().

import numpy as np
from docarray import DocumentArray

da = DocumentArray.from_files('*.jpg')
da.embeddings = np.random.random([len(da), 10])
da.match(da)
da[0].plot_matches_sprites(top_k=5, channel_axis=-1, inv_normalize=False)
../../../_images/sprite-match.png

Embedding projector#

Important

This feature requires fastapi dependency. You can do pip install "docarray[full]" to install it.

If a DocumentArray has .embeddings, you can visualize the embeddings interactively using plot_embeddings().

import numpy as np
from docarray import DocumentArray

docs = DocumentArray.empty(1000)
docs.embeddings = np.random.random([len(docs), 256])

docs.plot_embeddings()
../../../_images/embedding-projector-empty.gif

For image DocumentArray, you can do one step more to attach the image sprite on to the visualization points.

da.plot_embeddings(image_sprites=True)
../../../_images/embedding-projector.gif