图像源应用程序的服务器(在Expo上提供)。图像源有助于发送图像、获取图像预测和训练图像模型。
image-source-server的Python项目详细描述
图像源服务器
Image Source应用程序的服务器
使用量
- 如果您还没有安装Flask(如果您有水蟒,则会预先安装烧瓶)
pip install Flask
- 安装映像源服务器。
pip install image_source_server
- 创建一个imagesourceserver对象,实现“train”和“predict”方法并将其传递到imagesourceserver构造函数(如下所示的示例)
from image_source_server import ImageSourceServer
def train(train_dir_uri, params):
print('Training on data from : ' + train_dir_uri)
print('Train params : ' + str(params))
return 'Trained' # return value is returned to the Image Source App in the HTTP Response
def predict(img_uri):
print('Predicting on ' + img_uri)
return 'Cat' # return value is returned to the Image Source App in the HTTP Response
serv = ImageSourceServer(train=train, predict=predict)
serv.run()
- 当应用程序上按下“train”按钮时,将使用包含训练图像的文件夹的uri调用“train”方法
train(train_dir_uri, params)
train_dir_uri - uri of the directory containing folders which in turn contain the images
params - training parameters (list of key-value pairs) passed from the Image Source app
- “predict”方法将使用应用程序提供的用于预测的图像的uri调用。predict方法返回的值将返回给应用程序,并显示为对用户的警告。
predict(image_uri)
image_uri - the uri of the image on which the prediction needs to be made
return value - will be converted to a string (if not already a string) and sent to the Image Source app. This string will be displayed as an alert to the user
- “serv.run()”启动服务器
- 安装Expo应用程序Play Store Link(虽然有一个面向iOS的Expo应用,但苹果不允许在Expo应用上运行其他应用iOS独立图像源应用程序将在未来发布。)
- 访问展会上的Image Source应用程序页面。扫描Expo Android应用程序上的二维码,打开图像源应用程序。
- 运行服务器脚本(并确保调用了“run”方法)
将应用程序配置为与服务器一起工作
- 转到图像源应用程序上的“设置”选项卡。
- 点击“添加”按钮。
- 在“主机”条目旁边,输入服务器的IP地址(例如:192.168.1.130)
- 在“端口”条目旁边,输入服务器的端口号。默认情况下,映像源服务器在端口12221上运行因此,如果尚未在imagesourceserver构造函数中传入参数以指定自定义端口,请在此处输入12221。
- 点击“保存”
- 映像源应用程序现在配置为将数据发送到指定的服务器。您也可以添加其他服务器(但必须添加一个服务器)
管理和发送数据
- 单击“选择图像”,然后选择图像及其类别。
- 单击“提交”将图像添加到应用程序中。
- 当需要将图片传输到服务器时,单击“将所有图像发送到服务器”这会将所有图像传输到服务器然后,您可以检查运行服务器的文件夹上的“data/images”目录,以检查接收到的图片
培训
- 转到图像源应用程序上的“训练”选项卡。
- 点击“添加参数”添加训练参数训练参数是关键值对。所有的键值对都将被发送到服务器,然后服务器将其传递给“train”方法
- 点击“训练”按钮开始训练
预测
- 转到图像源应用程序上的“预测”选项卡。
- 选择要发送到服务器进行预测的图像
- 点击“提交”
- 图像将发送到服务器,一旦服务器响应,预测将显示为警报。
- 单击“选择图像”,然后选择图像及其类别。
- 单击“提交”将图像添加到应用程序中。
- 当需要将图片传输到服务器时,单击“将所有图像发送到服务器”这会将所有图像传输到服务器然后,您可以检查运行服务器的文件夹上的“data/images”目录,以检查接收到的图片