Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

How to send an image that was sent with a post request to a model for prediction

@app.route('/', methods = ['POST'])
def predict():
    if request.method == 'POST':
        base64img = request.get_json()['img'].encode('utf-8')

        img = base64.b64decode(base64img)
        with open('imgtemp.png', 'wb') as f:
            f.write(img)

        img = cv2.imread('imgtemp.png', 1)
    
        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

        payload = {
            'instances': [{'input_image': img.tolist()}]
        }

        r = requests.post(url, json = payload)
        pred = json.loads(r.content.decode('utf-8'))

        return pred
Comment

PREVIOUS NEXT
Code Example
Python :: Trying to use image in Flask website only shows broken img icon 
Python :: how to click button and download a file using robot frame work or selenium, it not contains link 
Python :: how to seperate the script from html template when using jQuery in flask 
Python :: Pull data from one couchdb doc via ids in another (Python) 
Python :: cuenta atras segundero python 
Python :: python socket backlog 
Python :: get command line variables python 
Python :: Retry function for sending data 
Python :: np sign no 0 
Python :: Frog Jump time complexity 
Python :: ring for loop 
Python :: ring PostgreSQL load the postgresqllib.ring library 
Python :: plotly scatter add annotation / text 
Python :: send whats app message using python 
Python :: how to get only the string of the input not the spaces arournd it in python 
Python :: size of variable 
Python :: django recapcha 
Python :: dice throw program in python 
Python :: custom 3d image generator for segmentation 
Python :: heatmap choos format for annotation 
Python :: voilion plot 
Python :: opencv houghlines only horizontal 
Python :: Pandas: Filter column value in array/list - ValueError: The truth value of a Series is ambiguous 
Python :: entry point not found python.exe 
Python :: kivy video recorder 
Python :: pass parameters to a odoo wizard 
Python :: discord py replace characters from string 
Python :: /bin/sh: 1: python: not found code runner 
Python :: manipulation 
Python :: python read text on screen 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =