Streamlit —使用数据应用程序更好地测试模型

介绍 (Introduction)

We use all kinds of techniques from creating a very reliable validation set to using k-fold cross-validation or coming up with all sorts of fancy metrics to determine how good our model performs. However, nothing beats looking at the raw output. When you look at sample output, you figure out things that none of the other methods can tell you.

我们使用各种技术,从创建非常可靠的验证集到使用k倍交叉验证或提出各种幻想指标来确定模型的性能。 但是,看原始输出无所不能。 查看示例输出时,您会发现其他方法无法告诉您的内容。

For example, if you are performing object detection on crops, you might see that when the crop is aligned in a certain way because of the wind, our bounding boxes don’t encapsulate the crop properly.

例如,如果要对农作物执行对象检测,则可能会看到,由于风将农作物以某种方式对齐时,我们的边界框无法正确封装农作物。

However, looking at sample outputs is a tedious task. Say we want to test various NMS values, and we also want to test it on a bunch of images. We can always write a function for this, but running it, again and again, is boring.

但是,查看样本输出是一项繁琐的任务。 假设我们要测试各种NMS值,并且还要对一堆图像进行测试。 我们总是可以为此编写一个函数,但是一次又一次地运行它很无聊。

Wouldn’t it be nice to have an app where we can upload an image and use a slider to adjust the NMS value? Welcome, Streamlit.

拥有一个可以上传图像并使用滑块调整NMS值的应用程序不是很好吗? 欢迎,Streamlit。

Image for post

什么是Streamlit? (What is Streamlit?)

According to their website, Streamlit is an open-source web framework for data scientists and machine learning engineers to create beautiful, performant apps in just a few hours, all in pure Python.

根据他们的网站,Streamlit是一个开放源代码Web框架,供数据科学家和机器学习工程师在短短几个小时内使用纯Python编写漂亮,高性能的应用程序。

安装 (Installation)

pip install streamlit

入门 (Getting started)

For this demo, I will be using the model I trained for wheat object detection using a FasterRCNN. You can go back to that article, train or, download my model and then follow along.

对于此演示,我将使用经过FasterRCNN训练用于小麦对象检测的模型 。 您可以返回该文章,进行培训或下载我的模型,然后继续学习。

Streamlit is just a standard python file run from top to bottom. We will start by creating a file called app.py, and writing the following code in it.

Streamlit只是从上到下运行的标准python文件。 我们将从创建一个名为app.py的文件开始,并在其中写入以下代码。

Image for post

We will run this as follows:

我们将如下运行:

streamlit run app.py

It will open up our browser with the following output.

它将打开我们的浏览器,并显示以下输出。

Image for post

Notice that we used a # inside st.write(). This indicates that we are writing markdown inside it. The first thing we need is a file uploader to upload images to Streamlit. Again, this is as simple as doing:

注意,我们在st.write()中使用了#。 这表明我们正在其中编写markdown。 我们需要的第一件事是文件上传器,将图像上传到Streamlit。 同样,这很简单:

Image for post

We pass the type of files allowed (jpg and png in this case), and when we do attach one, we read it using PIL. When we save app.py now:

我们传递允许的文件类型(在这种情况下为jpg和png),当我们附加一个文件时,我们使用PIL进行读取。 当我们现在保存app.py时:

Image for post

we see that Streamlit identifies that the source file has changed and asks if we want to rerun. And we do. Hence, we select “always rerun” for change to reflect automatically. Now our browser looks like this:

我们看到Streamlit确定源文件已更改,并询问是否要重新运行。 我们做。 因此,我们选择“始终重新运行”进行更改以自动反映。 现在,我们的浏览器如下所示:

Image for post

To display the image, we can use st.image(). However, after generating predictions, we want to replace the input image with our predicted image. To do so, we create an empty container and display everything in it.

要显示图像,我们可以使用st.image()。 但是,在生成预测后,我们希望将输入图像替换为预测图像。 为此,我们创建一个空容器并显示其中的所有内容。

Image for post

Another thing I like about using a container is that you can set use_column_width = True, and you won’t have to worry about image resizing. Now we can drag and drop images into our app.

我喜欢使用容器的另一件事是,您可以设置use_column_width = True,而不必担心图像调整大小。 现在我们可以将图像拖放到我们的应用程序中。

Image for post

Finally, we can convert our image to a tensor, load our model, generate outputs, and write it to our container.

最后,我们可以将图像转换为张量,加载模型,生成输出,并将其写入容器。

Image for post

To vary NMS values, we can either use a slider or an input box to type the value or use the ‘+’ and ‘-’ buttons to increase or decrease the value. I’m going to go with the slider. Our code changes to.

要更改NMS值,我们可以使用滑块或输入框键入值,也可以使用“ +”和“-”按钮增大或减小值。 我将使用滑块。 我们的代码更改为。

Image for post

And that’s it. In about just 50 lines of code, we can create this super useful app to test our model. You can also create templates for various problems like image classification, segmentation, object detection, and so on and use them every time you train a new model.

就是这样。 在大约50行代码中,我们可以创建这个超级有用的应用程序来测试我们的模型。 您还可以针对各种问题(例如图像分类,分割,对象检测等)创建模板,并在每次训练新模型时使用它们。

Finally, when we change the NMS values using the slider, if we’ve already generated predictions for a particular value, we don’t want to generate them again. Hence you can stick a simple decorator on top of the function:

最后,当我们使用滑块更改NMS值时,如果我们已经生成了特定值的预测,则我们不想再次生成它们。 因此,您可以在该函数之上粘贴一个简单的装饰器:

Image for post

and it will cache the results for you. This way it won’t rerun the same threshold every time but just used the cached result. Cool, isn’t it?

它将为您缓存结果。 这样,它不会每次都重新运行相同的阈值,而只是使用了缓存的结果。 不错,不是吗?

结论: (Conclusion:)

That will be it for this article. I would really recommend everyone to use Streamlit and create data apps. It works well for all kinds of data and caching helps with expensive operations like working with large data frames. Give it a try.

本文就是这样。 我真的建议大家使用Streamlit并创建数据应用程序。 它适用于所有类型的数据,并且缓存有助于处理昂贵的操作,例如处理大型数据帧。 试试看。

If you want to learn more about deep learning check out my deep learning series.

如果您想了解有关深度学习的更多信息,请查看我的深度学习系列。

~happy learning

〜快乐学习

翻译自: https://towardsdatascience.com/streamlit-use-data-apps-to-better-test-your-model-4a14dad235f5

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/390719.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

X Window系统

X Window系统 一种以位图方式显示的软件窗口系统。诞生于1984,比Microsoft Windows要早。是一套独立于内核的软件 Linux上的X Window系统 X Window系统由三个基本元素组成:X Server、X Client和二者通信的通道。 X Server:是控制输出及输入…

lasso回归和岭回归_如何计划新产品和服务机会的回归

lasso回归和岭回归Marketers sometimes have to be creative to offer customers something new without the luxury of that new item being a brand-new product or built-from-scratch service. In fact, incrementally introducing features is familiar to marketers of c…

Linux 设备管理和进程管理

设备管理 Linux系统中设备是用文件来表示的,每种设备都被抽象为设备文件的形式,这样,就给应用程序一个一致的文件界面,方便应用程序和操作系统之间的通信。 设备文件集中放置在/dev目录下,一般有几千个,不…

贝叶斯 定理_贝叶斯定理实际上是一个直观的分数

贝叶斯 定理Bayes’ Theorem is one of the most known to the field of probability, and it is used often as a baseline model in machine learning. It is, however, too often memorized and chanted by people who don’t really know what P(B|E) P(E|B) * P(B) / P(E…

文本数据可视化_如何使用TextHero快速预处理和可视化文本数据

文本数据可视化自然语言处理 (Natural Language Processing) When we are working on any NLP project or competition, we spend most of our time on preprocessing the text such as removing digits, punctuations, stopwords, whitespaces, etc and sometimes visualizati…

linux shell 编程

shell的作用 shell是用户和系统内核之间的接口程序shell是命令解释器 shell程序 Shell程序的特点及用途: shell程序可以认为是将shell命令按照控制结构组织到一个文本文件中,批量的交给shell去执行 不同的shell解释器使用不同的shell命令语法 shell…

真实感人故事_您的数据可以告诉您真实故事吗?

真实感人故事Many are passionate about Data Analytics. Many love matplotlib and Seaborn. Many enjoy designing and working on Classifiers. We are quick to grab a data set and launch Jupyter Notebook, import pandas and NumPy and get to work. But wait a minute…

转:防止跨站攻击,安全过滤

转:http://blog.csdn.net/zpf0918/article/details/43952511 Spring MVC防御CSRF、XSS和SQL注入攻击 本文说一下SpringMVC如何防御CSRF(Cross-site request forgery跨站请求伪造)和XSS(Cross site script跨站脚本攻击)。 说说CSRF 对CSRF来说,其实Spring…

Linux c编程

c语言标准 ANSI CPOSIX(提高UNIX程序可移植性)SVID(POSIX的扩展超集)XPG(X/Open可移植性指南)GNU C(唯一能编译Linux内核的编译器) gcc 简介 名称: GNU project C an…

k均值算法 二分k均值算法_使用K均值对加勒比珊瑚礁进行分类

k均值算法 二分k均值算法Have you ever seen a Caribbean reef? Well if you haven’t, prepare yourself.您见过加勒比礁吗? 好吧,如果没有,请做好准备。 Today, we will be answering a question that, at face value, appears quite sim…

新建VUX项目

使用Vue-cli安装Vux2 特别注意配置vux-loader。来自为知笔记(Wiz)

衡量试卷难度信度_我们可以通过数字来衡量语言难度吗?

衡量试卷难度信度Without a doubt, the world is “growing smaller” in terms of our access to people and content from other countries and cultures. Even the COVID-19 pandemic, which has curtailed international travel, has led to increasing virtual interactio…

Linux 题目总结

守护进程的工作就是打开一个端口,并且等待(Listen)进入连接。 如果客户端发起一个连接请求,守护进程就创建(Fork)一个子进程响应这个连接,而主进程继续监听其他的服务请求。 xinetd能够同时监听…

《精通Spring4.X企业应用开发实战》读后感第二章

一、配置Maven\tomcat https://www.cnblogs.com/Miracle-Maker/articles/6476687.html https://www.cnblogs.com/Knowledge-has-no-limit/p/7240585.html 二、创建数据库表 DROP DATABASE IF EXISTS sampledb; CREATE DATABASE sampledb DEFAULT CHARACTER SET utf8; USE sampl…

视图可视化 后台_如何在单视图中可视化复杂的多层主题

视图可视化 后台Sometimes a dataset can tell many stories. Trying to show them all in a single visualization is great, but can be too much of a good thing. How do you avoid information overload without oversimplification?有时数据集可以讲述许多故事。 试图在…

一步一步构建自己的管理系统①

2019独角兽企业重金招聘Python工程师标准>>> 系统肯定要先选一个基础框架。 还算比较熟悉Spring. 就选Spring boot postgres mybatis. 前端用Angular. 开始搭开发环境,开在window上整的。 到时候再放到服务器上。 自己也去整了个小服务器,…

python边玩边学_边听边学数据科学

python边玩边学Podcasts are a fun way to learn new stuff about the topics you like. Podcast hosts have to find a way to explain complex ideas in simple terms because no one would understand them otherwise 🙂 In this article I present a few episod…

react css多个变量_如何使用CSS变量和React上下文创建主题引擎

react css多个变量CSS variables are really cool. You can use them for a lot of things, like applying themes in your application with ease. CSS变量真的很棒。 您可以将它们用于很多事情,例如轻松地在应用程序中应用主题。 In this tutorial Ill show you …

vue 自定义 移动端筛选条件

1.创建组件 components/FilterBar/FilterBar.vue <template><div class"filterbar" :style"{top: top px}"><div class"container"><div class"row"><divclass"col":class"{selected: ind…

PPPOE拨号上网流程及密码窃取具体实现

楼主学生党一枚&#xff0c;最近研究netkeeper有些许心得。 关于netkeeper是调用windows的rasdial来进行上网的东西&#xff0c;网上已经有一大堆&#xff0c;我就不赘述了。 本文主要讲解rasdial的部分核心过程&#xff0c;以及我们可以利用它来干些什么。 netkeeper中rasdial…