Commit 1f255500 authored by ymir's avatar ymir

request single perceptron

parent ba916875
Here are some examples for each possible resource and actions
***** PERCEPTRON *****
-> random
python3 neuralnetworktrainercli.py random perceptron -d 784 18 16 10 -c "random perceptron" -o /tmp/perceptron.gz
PERCEPTRON_FILE=/tmp/perceptron.gz
-> randomize
rm ${PERCEPTRON_FILE}
python3 neuralnetworktrainercli.py randomize perceptron -d 784 18 16 10 -c "randomized perceptron" -a ${PERCEPTRON_FILE}
ls -lh ${PERCEPTRON_FILE}
-> create
PERCEPTRON_ID=`python3 neuralnetworktrainercli.py create perceptron -a ${PERCEPTRON_FILE}`
echo ${PERCEPTRON_ID}
-> read
rm ${PERCEPTRON_FILE}
python3 neuralnetworktrainercli.py read perceptron -i ${PERCEPTRON_ID} -a ${PERCEPTRON_FILE}
ls -lh ${PERCEPTRON_FILE}
-> update
python3 neuralnetworktrainercli.py update perceptron -i ${PERCEPTRON_ID} -a ${PERCEPTRON_FILE}
-> patch
python3 neuralnetworktrainercli.py patch perceptron -i ${PERCEPTRON_ID} -c "patched perceptron"
-> summarize
python3 neuralnetworktrainercli.py summarize perceptron -i ${PERCEPTRON_ID}
-> delete
python3 neuralnetworktrainercli.py delete perceptron -i ${PERCEPTRON_ID}
***** TRAINING SET *****
***** TRAINING SESSION *****
***** TRAINER *****
......
......@@ -5,7 +5,7 @@ from pythoncommontools.configurationLoader import configurationLoader
from os import sep
from os.path import join, realpath
from argparse import ArgumentParser
from requests import post
from requests import post, get, put, patch, delete
from json import dumps
from enum import Enum, unique
import sys
......@@ -23,12 +23,12 @@ configuration=configurationLoader.loadedConfiguration["service"]
baseURL="http://"+configuration["host"]+":"+configuration["port"]+"/"+configuration["endpoint"]
# initialize parser
parser = ArgumentParser()
parser.add_argument("action", type=str, help="the action to execute : randomize, create, read, update, delete, summarize, patch")
parser.add_argument("action", type=str, help="the action to execute : randomize, create, read, update, delete, summarize, patch, start, stop")
parser.add_argument("resource", type=str, help="the type of resource to use : perceptron, trainingset, trainingsession, trainer")
parser.add_argument("-a", "--archive", type=str, help="file to archive resource")
parser.add_argument("-c", "--comments", type=str, help="any free text that can help you")
parser.add_argument("-d", "--dimensions", type=int, nargs='+', help="ordered perceptrons layers sizes, i.e. 784 18 16 10")
parser.add_argument("-i", "--id", type=int, help="specific ID for the resource")
parser.add_argument("-o", "--output", type=str, help="file to write result")
# display extra help
def displayExtraHelp():
file = open(extraHelpFile, 'r')
......@@ -38,26 +38,82 @@ def displayExtraHelp():
# check response
def checkresponse(response):
assert response.status_code==200, str(response.status_code) + " " + response.reason + " : " + response.text
# dump response
def dumpResponse(output,content):
file = open(output, "wb")
# dump archive
def dumpArchive(archive,content):
file = open(archive, "wb")
file.write(content)
file.close()
# def randomize perceptron
def randomizePerceptron(dimensions,comments,output):
# load archive
def loadArchive(archive):
file = open(archive, "rb")
content=file.read()
file.close()
return content
# randomize perceptron
def randomizePerceptron(dimensions,comments,archive):
URL=baseURL+"/perceptron/random"
data=dumps({"dimensions":dimensions,"comments":comments})
response = post(URL, data=data, headers=ContentType.GZIP.value)
checkresponse(response)
dumpResponse(output, response.content)
dumpArchive(archive, response.content)
pass
# create perceptron
def createPerceptron(archive):
URL=baseURL+"/perceptron"
data=loadArchive(archive)
response = post(URL, data=data, headers=ContentType.GZIP.value)
checkresponse(response)
print(response.text)
pass
# read perceptron
def readPerceptron(id,archive):
URL=baseURL+"/perceptron/"+str(id)
response = get(URL, headers=ContentType.GZIP.value)
checkresponse(response)
dumpArchive(archive, response.content)
pass
# update perceptron
def updatePerceptron(id,archive):
URL=baseURL+"/perceptron/"+str(id)
data=loadArchive(archive)
response = put(URL, data=data, headers=ContentType.GZIP.value)
checkresponse(response)
pass
# patch perceptron
def patchPerceptron(id,comments):
URL=baseURL+"/perceptron/"+str(id)
data=dumps({"comments":comments})
response = patch(URL, data=data, headers=ContentType.GZIP.value)
checkresponse(response)
pass
# summarize perceptron
def summarizePerceptron(id):
URL=baseURL+"/perceptron/"+str(id)+"/summary"
response = get(URL, headers=ContentType.JSON.value)
checkresponse(response)
print(response.text)
pass
# delete perceptron
def deletePerceptron(id):
URL=baseURL+"/perceptron/"+str(id)
response = delete(URL, headers=ContentType.JSON.value)
checkresponse(response)
pass
# parse arguments
def dispatchRequest(arguments):
if arguments.action.upper()=="RANDOMIZE" and arguments.resource.upper()=="PERCEPTRON": randomizePerceptron(arguments.dimensions,arguments.comments,arguments.output)
if arguments.action.upper()=="RANDOMIZE" and arguments.resource.upper()=="PERCEPTRON": randomizePerceptron(arguments.dimensions,arguments.comments,arguments.archive)
elif arguments.action.upper()=="CREATE" and arguments.resource.upper()=="PERCEPTRON": createPerceptron(arguments.archive)
elif arguments.action.upper()=="READ" and arguments.resource.upper()=="PERCEPTRON": readPerceptron(arguments.id,arguments.archive)
elif arguments.action.upper()=="UPDATE" and arguments.resource.upper()=="PERCEPTRON": updatePerceptron(arguments.id,arguments.archive)
elif arguments.action.upper()=="PATCH" and arguments.resource.upper()=="PERCEPTRON": patchPerceptron(arguments.id,arguments.comments)
elif arguments.action.upper()=="SUMMARIZE" and arguments.resource.upper()=="PERCEPTRON": summarizePerceptron(arguments.id)
elif arguments.action.upper()=="DELETE" and arguments.resource.upper()=="PERCEPTRON": deletePerceptron(arguments.id)
else: raise Exception("couple action/resource does not match : " + arguments.action + "/" + arguments.resource)
pass
# run program
if __name__ == "__main__":
if len(sys.argv)==1 or sys.argv[1].upper() in ("-H","--HELP",): displayExtraHelp()
arguments = parser.parse_args()
dispatchRequest(arguments)
pass
pass
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment