Image scene recognition is one of the entry-level programs of DL + computer vision processing, so the first step in building the AI display framework is to realize image scene recognition based on flash.
The whole process is very simple, and the steps are as follows:
(1) set HTML script for image selection and upload
<div class="box box-primary"> <form role="form" action="{{ url_for('cv_image_recognize') }}" method="post" enctype="multipart/form-data" > <div class="box-body"> <div class="form-group"> <label>Image scene recognition model:</label> <select class="form-control" name='selectmodel'> {% for modelname in modelnames %} <option>{{ modelname }}</option> {% endfor %} </select> </div> <div class="form-group"> <label>Return result TopK Value:</label> <select class="form-control" name='topk'> <option>1</option> <option>3</option> <option>5</option> <option selected="selected" >10</option> </select> </div> <div class="form-group"> <label for="exampleInputFile">Select an image(.jpg, .png, .bmp etc.)</label> <input type="file" name=file id="exampleInputFile" value="Select image" > </div> </div> <div class="box-footer"> <input type="submit" value="Upload and forecast" name="predict"/> </div> </form> </div>
(2) procedures for setting response
@app.route('/cv_image_recognize', methods=['GET', 'POST']) def cv_image_recognize(): print('upload image and predict...') #print(request.method) if request.method == 'POST': if 'file' not in request.files: print('No file part') return redirect(request.url) file = request.files['file'] arch = request.form['selectmodel'] topk = 5 try: topk = int(request.form['topk']) except: topk = 5 # Upload files to static folder uploadfile = os.path.join(app.config['UPLOAD_FOLDER'], file.filename) if file and func.allowed_file(file.filename): file.save(uploadfile) #with tempfile.NamedTemporaryFile() as temp: # form.input_photo.data.save(temp) # temp.flush() #image_binary = image.read() classlist,totaltime = imagenet_logits.RecognizeScene(ai_dir,arch, uploadfile, topk)#detect_objects(temp.name) photo_form = PhotoForm(request.form) return render_template('cv/image_recognize.html', header='Picture scene recognition',description='Using deep learning+imagenet To realize the classification and recognition of natural image scene,Namely what is in the picture. ', update_date='2019-04-15',current_user=current_user, modelnames=model_list, filename=file.filename, classlist=classlist,totaltime=totaltime) else: return render_template('cv/image_recognize.html', header='Picture scene recognition',description='Using deep learning+imagenet To realize the classification and recognition of natural image scene,Namely what is in the picture. ', update_date='2019-04-15',current_user=current_user, filename='',modelnames=model_list, result={})
(3) main algorithm processing module
This program integrates many models, which is a very good image recognition framework.
The specific implementation effect is as follows:
In the specific implementation process, users can dynamically select any model:
['alexnet', 'bninception', 'cafferesnet101', 'densenet121', 'densenet161', 'densenet169', 'densenet201', 'dpn107', 'dpn131', 'dpn68', 'dpn68b', 'dpn92', 'dpn98', 'fbresnet152', 'inceptionresnetv2', 'inceptionv3', 'inceptionv4', 'nasnetalarge', 'nasnetamobile', 'pnasnet5large', 'polynet', 'resnet101', 'resnet152', 'resnet18', 'resnet34', 'resnet50', 'resnext101_32x4d', 'resnext101_64x4d', 'se_resnet101', 'se_resnet152', 'se_resnet50', 'se_resnext101_32x4d', 'se_resnext50_32x4d', 'senet154', 'squeezenet1_0', 'squeezenet1_1', 'vgg11', 'vgg11_bn', 'vgg13', 'vgg13_bn', 'vgg16', 'vgg16_bn', 'vgg19', 'vgg19_bn', 'xception']
It also supports the user to set the number of topk s returned.