def test_predict(self): tests = [("<?php echo 1+1; ?>", 1), ('<?php system("ls"); ?>', 0)] p = predict.Predictor("./model/model.joblib") tmp_file = "/tmp/tmp.php" for t in tests: with open(tmp_file, "w") as f: f.write(t[0]) result = p.predict(tmp_file) print(result) self.assertEqual(result, t[1])
def initPredictor(): global predictor max_gram = 5 tokenizer = predict.Tokenizer() tokens = [] tokens = tokens + tokenizer.tokenize_file("data/bee_movie.txt") tokens = tokens + tokenizer.tokenize_file("data/moby_dick.txt") tokens = tokens + tokenizer.tokenize_file("data/the_iliad.txt") predictor = predict.Predictor(tokens, tokenizer, max_gram)
def add_predictor(self, predictor_name): if predictor_name == setting.PREDICTOR_DEFAULT: self.predictor = predict.Predictor() elif predictor_name == setting.PREDICTOR_SIMPLE: self.predictor = predict.SimplePredictor() elif predictor_name == setting.PREDICTOR_Q: self.predictor = predict.QPredictor() self.predictor.init(self.switch_num) elif predictor_name == setting.PREDICTOR_DQN: self.predictor = predict.DQNPredictor() self.predictor.init(self.switch_num) else: raise NameError('Error. No such predictor. Exit') return
def _actualrun(self): self.pickle_and_call('DPPP {}'.format(self.ddecal2)) self.fix_h5('prephase.h5') self.pickle_and_call('DPPP {}'.format(self.acal2)) # self.pickle_and_call('DPPP {}'.format(self.ddecal_diag)) # self.fix_h5('prephase2.h5', True) # self.pickle_and_call('DPPP {}'.format(self.acal_diag)) self._init_losoto() self.pickle_and_call(self.losoto_p) # self.pickle_and_call(self.losoto_a) self.pickle_and_call('DPPP {}'.format(self.ddecal_pu)) self.fix_folders() predictor = pr.Predictor(self.ms, self.predict_path, self.fpath, self.pset_loc) predictor.initialize() predictor.execute() os.mkdir('{}/losoto'.format(self.ms))
def main(): max_gram = 3 tokenizer = predict.Tokenizer() tokens = [] tokens = tokens + tokenizer.tokenize_file("data/bee_movie.txt") tokens = tokens + tokenizer.tokenize_file("data/moby_dick.txt") predictor = predict.Predictor(tokens, tokenizer, max_gram) while True: user_input = input("~> ") if user_input == ":q": return predicted = predictor.get_prediction(user_input) print(json.dumps(predicted.most_common(10)))
def setModel(self, modelFilePath): self.model = predict.Predictor(modelFilePath)
import predict import determine_position import numpy as np def convert_frame(a, b, c, T): x = np.array([[a, b, c, 1]]).T y = (T @ x).squeeze() return y[0], y[1], y[2] # load the trained model # TODO determine path predictor = predict.Predictor(ckpt_path='20000.pth') # let the robot touch one edge # 1st point on edge N = 3 # take 3 points along an edge and take average a1, b1, c1 = [0] * N, [0] * N, [0] * N a2, b2, c2 = [0] * N, [0] * N, [0] * N for i in range(N): depth_map0 = from_robot() # TODO (400,) ndarray, some assumed API a1[i], b1[i], c1[i], a2[i], b2[i], c2[i] = predictor.predict(depth_map0) a1[i], b1[i], c1[i], a2[i], b2[i], c2[i] = a1[i].item(), b1[i].item(), c1[i].item(), a2[i].item(), b2[i].item(), c2[i].item() a1 = sum(a1) / N b1 = sum(b1) / N c1 = sum(c1) / N a2 = sum(a2) / N b2 = sum(b2) / N c2 = sum(c2) / N
#!/usr/bin/env python import time import cv2 import predict import numpy as np import sys import rospy CLASSES = [ 'forward', 'backward', 'left', 'right', 'stop', 'fleft', 'fright', 'bleft', 'bright' ] predictor = predict.Predictor(sys.argv[1], sys.argv[2]) from sensor_msgs.msg import Image, CameraInfo from cv_bridge import CvBridge, CvBridgeError class Exp: def __init__(self): self.output = None self.ori = None self.blur = None self.mask = None self.data_methods = ['blur', 'mask', 'ori', 'output'] self.classes = [ 'forward', 'backward', 'left', 'right', 'stop', 'fleft', 'fright', 'bleft', 'bright' ]
import socketio import predict sio = socketio.Client() pr = predict.Predictor() @sio.on("connect") def on_connect(): print("I\'m Connected!") @sio.on("message") def on_message(data): print("I received a message: " + str(data)) @sio.on("disconnect") def on_disconnect(): print("I\'m Disonnected!") if __name__ == "__main__": sio.connect("http://joshuayuan.me:8080") pr.start(sio) # sio.emit("pi:server", {"msg": "actually new message!"})
import numpy as np import pandas as pd import preprocess as prep import predict as tr STK = pd.read_csv("GOOGL.csv") if len(STK) == 0: print("no csv data") exit() dataPrep = prep.DataPrep("quandl", STK) features, labels = dataPrep.stk2ind() RF = tr.Predictor(features, labels, "rf") RF.test()