What does computer vision see in the 2020-US Election news feed? (Part 2/2)
By: Srinivas Vadrevu
Tags: Python, Artificial Intelligence, Data Science, Data Visualization, Trump

person= You; #yes its you,dear reader!

print("Thanks for viewing this article")



print("Please check out the Part 1 of this series..") If Person.read_article( Part1 )= False:print("Please check out the Part 1 of this series..")

urlopen( urlopen( Part1 ) #please click on the Part1 hyperlink unlock(Part2) # else unlock part2

print("Please scroll down. Happy reading!") |



As I write this line, US elections are inching closer to the brink. The Biden-Trump count stands at 264–213 and Biden needs 6 more to win the election. As I wonder how narrow the margins (224–213) were a while ago, I think these numbers stem from their campaigns' vigor and the press coverage of it for over a year. After reading part 1, you now have an extensive image analytical dataset on US elections, and you are ready to churn it through the visualization engine for insights. This article is intended to be more of a guide to visualizing image analytics rather than the insights themselves. So, I begin with the code, explanations, and structure of the visualization first and later proceed to a few insights from the news feed

2A) Visualization approach, code, and illustration of image analytics data

Photo by Library of Congress on Unsplash

For illustration purposes, I collected a stock of images from Unsplash to show how to process and visualize data in image grids. Yes, we will plot the images on axes like how you plot data points!

So, I searched for “Donald Trump” and “Joe Biden” on unsplash.com to source about 15–20 images for each of the query terms.

For these batches of URLs for “Donald Trump” and “Joe Biden,” I called the runvisionai function ( see Part1 for more, if you bypassed the opening code) to build extensive feature category level datasets.

Do you recall the label_df data frame? I assign it or a subset of it to test_label.

test_label=label_df['source_term'=="Donald Trump_site:Unsplash.com"

test_label['Query/alt'].fillna("NA", inplace = True)

test_label=test_label.sort_values(["img_num"],ascending=(True))

display_images(test_label)

From here, there are many possible ways in which you can visualize the image datasets. TI wanted to build a view that gives me a one-stop overview of all the images in a grid and the corresponding feature charts for each image in another grid similar to the first image-grid structure.

Say, I would like to display a grid of all the images in this subset of Donald Trump images where Cloud vision API has annotated at least one label. I want to design a function that allows me to pass the subset ‘test_label’ data frame and retrieve a grid of images. A sketch of the requirement to create my code schema looks like this:

Fig 1: Sketch for representing the images in a grid-like manner

I need the main plot for the entire grid and subplot for each URL image for the image-grid. (Gist2) →

I pass the batch of image URLs and extract distinct URLs(Gist2)

Basis the count of images, I set my subplot dimensions (rows, columns, width, and height). I capped the columns of the grid to 4 for easier readability.

For each URL, I will use the Python Imaging Library (PIL) to open, read and convert the URL into a PIL image (function in Gist1 called in Gist2)→

Loop runs for each URL show the image in each subplot and repeats it till all images are plotted.

Gist 1: Function to return PIL image from URL

Gist 2: Plot the images in a grid

2a.1 Label identification and visualization :

The output of the above function is a one-stop overview grid of all the images for which Cloud Vision API identified at least one label. You can find it below: