flask渲染图像
After creating a Python-based machine learning application you might want to get it running on a website.
创建基于Python的机器学习应用程序后,您可能希望使其在网站上运行。
In this article it is explained how this can be realized with the microframework Flask for an image-based recommender system.
在本文中,说明了如何使用基于图像的推荐系统的微框架Flask来实现这一点。
We implement an image gallery on a website, the images can be selected, and similar images are displayed. Such a solution could be employed for example in online shops.
我们在网站上建立了图片库,可以选择图片,并显示类似的图片。 例如,可以在在线商店中采用这种解决方案。
The similarities are obtained by comparing feature vectors derived with a pretrained Resnet18 network as explained in a previous article. The results from this work are Pandas dataframes (essentially tables) with the names of most similar images and similarity values between zero (not similar) and one (most similar) for each image. These are stored and used here.
如上一篇文章所述,通过比较使用预训练的Resnet18网络导出的特征向量来获得相似性。 这项工作的结果是熊猫数据帧(基本上是表格),具有最相似图像的名称,并且每个图像的相似度值在零(不相似)和一个(最相似)之间。 这些在这里存储和使用。
In the next figure, in (a) the steps from the theory and implementation are sketched. This article focuses on part (b), where the dataframes have already been calculated offline to be used on a website.
在下图中,在(a)中概述了理论和实现的步骤。 本文重点介绍(b)部分,其中数据帧已离线计算以用于网站。
![Image for post](https://img-service.csdnimg.cn/img_convert/5b80bbf27c87cccbcb061804d5547d0b.png)
We will see how to
我们将看到如何
- install Flask and run the app locally on a debug server 安装Flask并在调试服务器上本地运行应用程序
- define needed routes — the URLs that are used for the gallery and the recommendations 定义所需的路线-用于画廊和推荐的URL
- transfer the needed information from the user input to the backend and the recommendations back to the user 将所需的信息从用户输入传递到后端,并将建议返回给用户
- implement a html/JavaScript gallery that suggests similar images 实现建议类似图像的html / JavaScript库
create pickle files based on my first two articles (theory, implementation with Jupyter notebook). Use them for top-k lists that define the recommended images.
根据我的前两篇文章( 理论 ,使用Jupyter notebook 实现 )创建pickle文件。 将它们用于定义推荐图像的前k个列表。
1.烧瓶 (1. Flask)
![Image for post](https://img-service.csdnimg.cn/img_convert/8804ac74c366dd85ccac98f4fe539e39.png)