机器学习数据的Python套接字
mlsocket的Python项目详细描述
M插座
MLSocket是在socket的python包之上构建的python包,通过tcp连接可以方便地发送和接收numpy数组和机器学习模型。在
- 免费软件:麻省理工学院许可证
MLSocket类继承了python内置的socket包,支持socket类的所有基本操作。 它不仅可以发送字节数据,还可以发送numpy数组和keras模型。在
安装
$ pip install mlsocket --user
特点
System | Linux | macOS | Windows |
---|---|---|---|
Status |
- 支持Windows 10、Ubuntu和macOs=>;在github操作上测试
- 支持numpy数组的数据传输
- 支持将keras模型数据传输为hdf5文件
- 支持scikit学习分类器的数据传输
- 支持python3.6、3.6、3.8=>;在github操作上测试
MLSocket继承内置python套接字的socket对象,但重写4个方法。在
- 在MLSocket.send(数据),MLSocket.sendall公司(data):发送数据。不像套接字.send,这两个函数总是表现出阻塞行为,即等待服务器的响应,服务器接收到所有发送的数据。在
- 在MLSocket.recv.插座(bufsize):接收给定大小的数据,但返回值不在bufsize的大小中。它将接收客户端发送的所有数据,步长为给定的bufsize。在
- 在MLSocket.accept():此函数与插座.接受(),但返回MLSocket对象和连接的地址。在
使用
MLSocket的基本用法通过发送和接收numpy数组和机器学习模型的服务器和客户机脚本演示。在
服务器端
^{pr2}$客户端
frommlsocketimportMLSocketfromkeras.modelsimportSequentialfromkeras.layersimportDensefromsklearnimportsvmimportnumpyasnpHOST='127.0.0.1'PORT=65432# Make an ndarraydata=np.array([1,2,3,4])# Make a keras modelmodel=Sequential()model.add(Dense(8,input_shape=(None,4)))model.compile(optimizer='adam',loss='binary_crossentropy')# Make a scikit-learn classifierclf=svm.SVC(gamma=0.00314)# Send datawithMLSocket()ass:s.connect((HOST,PORT))# Connect to the port and hosts.send(data)# After sending the data, it will wait until it receives the reponse from the servers.send(model)# This will wait as wells.send(clf)# Same
- 项目
标签: