Build an AI Image Diagnosing App_0

With the power of AI easily harnessed by Google open-sourcing its training data as well as code packages, it’s greatly easy and fast to build all sorts of apps to accomplish intellectual tasks that are impossible to pull off by individuals before.

Dozens of such tasks are possible and feasible. Now is the speed to push to market, to gain traction and stickiness, so either grow up big, or sell to big companies with accrued value.

Time is most valuable! Technicality is not a big problem, speed is.

Following the prototype guru Saraj generously shared, I set off to create a simple app as such:

It allows a user to upload an X-ray, and the app automatically and expediently exhibit the diagnosis: 98% probability is pneumonia, 43% it’s fibrosis. It greatly serve the market so people don’t need to go through tremendous hassles to see a doctor for this result, let alone a lot of people may not be able to afford to.

The key driver that makes it possible is Google has already conducted tons of foundational work by obtaining large number of images as well labeled diseases, trained and provide anyone to grab and use by

from keras.applications.resnet50 import ResNet50
from keras.preprocessing import image
from keras.applications.resnet50 import preprocess_input, decode_predictions

The diseases contains ‘Atelectasis’, ‘Consolidation’, ‘Infiltration’, ‘Pneumothorax’, ‘Edema’, ‘Emphysema’, ‘Fibrosis’, ‘Effusion’, ‘Pneumonia’, ‘Pleural_Thickening’, ‘Cardiomegaly’, ‘Nodule’, ‘Mass’, ‘Hernia’.

from flask import render_template, jsonify, Flask, redirect, url_for, request
from app import app
import random
import os
from keras.applications.resnet50 import ResNet50
from keras.preprocessing import image
from keras.applications.resnet50 import preprocess_input, decode_predictions
import numpy as np


@app.route('/')

#disease_list = ['Atelectasis', 'Consolidation', 'Infiltration', 'Pneumothorax', 'Edema', 'Emphysema', \
                  # 'Fibrosis', 'Effusion', 'Pneumonia', 'Pleural_Thickening', 'Cardiomegaly', 'Nodule', 'Mass', \
                  # 'Hernia']

@app.route('/upload')
def upload_file2():
   return render_template('index.html')
	
@app.route('/uploaded', methods = ['GET', 'POST'])
def upload_file():
   if request.method == 'POST':
      f = request.files['file']
      path = os.path.join(app.config['UPLOAD_FOLDER'], f.filename)
      model= ResNet50(weights='imagenet')
      img = image.load_img(path, target_size=(224,224))
      x = image.img_to_array(img)
      x = np.expand_dims(x, axis=0)
      x = preprocess_input(x)
      preds = model.predict(x)
      preds_decoded = decode_predictions(preds, top=3)[0] 
      print(decode_predictions(preds, top=3)[0])
      f.save(path)
      return render_template('uploaded.html', title='Success', predictions=preds_decoded, user_image=f.filename)


@app.route('/index')
def index():
    return render_template('index.html', title='Home')

@app.route('/map')
def map():
    return render_template('map.html', title='Map')


@app.route('/map/refresh', methods=['POST'])
def map_refresh():
    points = [(random.uniform(48.8434100, 48.8634100),
               random.uniform(2.3388000, 2.3588000))
              for _ in range(random.randint(2, 9))]
    return jsonify({'points': points})


@app.route('/contact')
def contact():
    return render_template('contact.html', title='Contact')

Even we just want to get started and don’t want to be fancy and sophisticated, it’s worthy to take a peek of existing commercial apps such as https://vidalung.ai/

Lastly, we need to know a broad group of AI applications on healthcare, captured by Saraj:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.