示例#1
0
文件: Irc.py 项目: randolf/Doger
def on_SIGHUP(signum, frame):
    cmd = Commands.commands.get("admin")
    if cmd and Config.config.get("irclog"):
        Logger.irclog("Received SIGHUP, reloading Config")
        req = Hooks.Request(Config.config["irclog"][0],
                            Config.config["irclog"][1], "@SIGHUP", "SIGHUP")
        Hooks.run_command(cmd, req, ["reload", "Config"])
示例#2
0
    def __init__(self, port, flag):
        self.reward_range = (-200,200)
        self.port=port
        self.flag=flag
	# Start flightgear sim and establish hooks, against other pilot

        time.sleep(flag/5)

        if (self.flag % 2 == 0):
            exec_string = "~/flightgear/dnc-managed/run_fgfs.sh --telnet=foo,bar,1000,foo,{},bar --aircraft=f15c --prop:/sim/rendering/multithreading-mode=AutomaticSelection --altitude=40000 --vc=400 --enable-fuel-freeze --geometry=300x300 --multiplay=out,10,127.0.0.1,{} --multiplay=in,10,127.0.0.1,{} --callsign=primary".format(self.port, self.port+1, self.port+501)
        else:
            exec_string = "~/flightgear/dnc-managed/run_fgfs.sh --telnet=foo,bar,1000,foo,{},bar --aircraft=f15c --prop:/sim/rendering/multithreading-mode=AutomaticSelection --altitude=40000 --vc=400 --enable-fuel-freeze --geometry=300x300 --multiplay=out,10,127.0.0.1,{} --multiplay=in,10,127.0.0.1,{} --callsign=primary".format(self.port, self.port+1, self.port-499)
        #os.system(exec_string)
        proc = subprocess.Popen([exec_string], shell=True,
             stdin=None, stdout=None, stderr=None, close_fds=True)
        time.sleep(30)
        self.hooks = Hooks.Hooks(port)

        out = self.hooks.starter()

        print(out, file=open("output.txt", "a"))

	# Actions of the agent (control schema)
        self.action_space = spaces.MultiDiscrete([3,3,3,3])

	# Observations of the agent (observation schema)

        high = np.array([
            1000,1000,10000,1000,1000,1000,10000,10000,10000,10000,10000,10000,1000,1000,10000,1000,1000,1000])

        self.observation_space = spaces.Box(-high, high, dtype=np.float16)
示例#3
0
    def run(self):
        import Hooks

        #now make sure that the kids can't setuid back to root
        groupToRunAs = getattr(Configuration, 'groupToRunAs', None)
        userToRunAs = getattr(Configuration, 'userToRunAs', None)
        if groupToRunAs is not None or userToRunAs is not None:
            # in case we are seteuid something else, which would
            # cause setuid or getuid to fail, undo any existing
            # seteuid. (The only reason to do this is for the case
            # os.getuid()==0, AFAIK).
            try:
                seteuid = os.seteuid
            except AttributeError:
                # the OS may not support seteuid, in which
                # case everything is hotsy-totsy.
                pass
            else:
                seteuid(os.getuid())
            if groupToRunAs is not None:
                gid = grp.getgrnam(groupToRunAs)[2]
                os.setgid(gid)

            if userToRunAs is not None:
                uid = pwd.getpwnam(userToRunAs)[2]
                os.setuid(uid)

        Hooks.ChildStart()
        SocketMan.run(self)
示例#4
0
def _as(req, arg):
	"""
	admin"""
	_, target, text = req.text.split(" ", 2)
	if target[0] == '@':
		Global.account_cache[""] = {"@": target[1:]}
		target = "@"
	if text.find(" ") == -1:
		command = text
		args = []
	else:
		command, args = text.split(" ", 1)
		args = [a for a in args.split(" ") if len(a) > 0]
	if command[0] != '_':
		cmd = commands.get(command.lower(), None)
		if not cmd.__doc__ or cmd.__doc__.find("admin") == -1 or Irc.is_admin(source):
			if cmd:
				req = Hooks.FakeRequest(req, target, text)
				Hooks.run_command(cmd, req, args)
示例#5
0
def _as(req, arg):
	"""
	admin"""
	_, target, text = req.text.split(" ", 2)
	if target[0] == '@':
		Global.account_cache[""] = {"@": target[1:]}
		target = "@"
	if text.find(" ") == -1:
		command = text
		args = []
	else:
		command, args = text.split(" ", 1)
		args = [a for a in args.split(" ") if len(a) > 0]
	if command[0] != '_':
		cmd = commands.get(command.lower(), None)
		if not cmd.__doc__ or cmd.__doc__.find("admin") == -1 or Irc.is_admin(source):
			if cmd:
				req = Hooks.FakeRequest(req, target, text)
				Hooks.run_command(cmd, req, args)
	if Global.account_cache.get("", None):
		del Global.account_cache[""]
示例#6
0
    def run(self):
        import Hooks

        #now make sure that the kids can't setuid back to root
        if hasattr(Configuration, 'groupToRunAs'):
            gid = grp.getgrnam(Configuration.groupToRunAs)[2]
            os.setgid(gid)

        if hasattr(Configuration, 'userToRunAs'):
            uid = pwd.getpwnam(Configuration.userToRunAs)[2]
            if hasattr(os, 'seteuid'):
                os.seteuid(os.getuid())
            os.setuid(uid)

        Hooks.ChildStart()
        SocketMan.run(self)
示例#7
0
def DistributedTrain(FLAGS, task_index, TFCluster, TFServer, QueueHook):
    is_chief = (task_index == 0)
    master = TFServer.target
    with tf.device(
            tf.train.replica_device_setter(
                worker_device="/job:worker/task:%d" % task_index,
                cluster=TFCluster)):
        #Import data
        mnist = input_data.read_data_sets(FLAGS.data_dir + "-" +
                                          str(task_index),
                                          one_hot=True)
        #PlaceHolder for Images
        x = tf.placeholder(tf.float32, [None, 784])
        #PlaceHolder for Labels-OneHot Vector
        y_ = tf.placeholder(tf.float32, [None, 10])
        #Build the Deep Model
        y_conv, keep_prob = Deep.deepnn(x)
        #Define loss and optimizer
        SummaryDictionary = {}
        global_step = tf.train.get_or_create_global_step()
        with tf.name_scope('loss'):
            cross_entropy = tf.nn.softmax_cross_entropy_with_logits(
                labels=y_, logits=y_conv)
        cross_entropy = tf.reduce_mean(cross_entropy)
        SummaryDictionary.update({'cross_entropy': cross_entropy})
        with tf.name_scope('adam_optimizer'):
            Optimizer = tf.train.AdamOptimizer(1e-4)
            SyncOtimizer = tf.train.SyncReplicasOptimizer(
                Optimizer,
                replicas_to_aggregate=FLAGS.workers,
                total_num_replicas=FLAGS.workers,
                use_locking=True,
                name="sync_replicas")
            train_step = SyncOtimizer.minimize(
                cross_entropy,
                global_step=global_step,
                aggregation_method=tf.AggregationMethod.ADD_N)
        #Define Metric
        with tf.name_scope('accuracy'):
            correct_prediction = tf.equal(tf.argmax(y_conv, 1),
                                          tf.argmax(y_, 1))
            correct_prediction = tf.cast(correct_prediction, tf.float32)
        accuracy = tf.reduce_mean(correct_prediction)
        SummaryDictionary.update({'AccuracyMetric': accuracy})
    #Added Summaries for TensorBoard Visualization.
    ListOfSummaries = []
    for key in SummaryDictionary:
        ListOfSummaries.append(tf.summary.scalar(key, SummaryDictionary[key]))
    #for key, value in (SummaryDictionary).iteritems():
    #	ListOfSummaries.append(tf.summary.scalar(key,value))
    MergedSummaryOperation = tf.summary.merge(ListOfSummaries)

    #BatchSize=FLAGS.batch_size
    BatchSize = int(FLAGS.batch_size / FLAGS.workers)
    SummarySteps = 100
    hooks = [QueueHook]
    #Hook for Sync replicas
    sync_replicas_hook = SyncOtimizer.make_session_run_hook(is_chief,
                                                            num_tokens=0)
    hooks.append(sync_replicas_hook)
    #Hook for StopAtStepHook
    hooks.append(tf.train.StopAtStepHook(FLAGS.Iterations))
    if is_chief:
        #Get training subset for validation
        TrainingLenght = mnist.train.images.shape[0]
        #idx=np.random.randint(TrainingLenght,size=int(TrainingLenght/10))
        idx = np.random.randint(TrainingLenght, size=BatchSize)
        TrainingImagesValidation = mnist.train.images[idx]
        #print(TrainingImagesValidation.shape)
        TrainingLabelsValidation = mnist.train.labels[idx]
        #print(TrainingLabelsValidation.shape)
        hooks.append(
            HOOKS.NewSummarySaverHook(MergedSummaryOperation,
                                      FLAGS.model_dir + "/Training",
                                      SummarySteps,
                                      FLAGS.Iterations,
                                      features=x,
                                      labels=y_,
                                      dropout=keep_prob,
                                      batchx=TrainingImagesValidation,
                                      batchy=TrainingLabelsValidation,
                                      dropout_value=1.0))
        hooks.append(
            HOOKS.FinalSummaryHook(SummaryDictionary, x, y_, keep_prob,
                                   mnist.test.images, mnist.test.labels, 1.0,
                                   FLAGS.Iterations, "Testing"))
    tick = time.time()
    Config = None
    with tf.train.MonitoredTrainingSession(master=master,
                                           is_chief=is_chief,
                                           hooks=hooks,
                                           checkpoint_dir=FLAGS.model_dir,
                                           save_checkpoint_secs=None,
                                           save_summaries_steps=None,
                                           save_summaries_secs=None,
                                           config=Config) as sess:
        step = sess.run(global_step)
        while not sess.should_stop():  #and step <= FLAGS.Iterations:
            batch = mnist.train.next_batch(BatchSize)
            _, step = sess.run([train_step, global_step],
                               feed_dict={
                                   x: batch[0],
                                   y_: batch[1],
                                   keep_prob: 0.5
                               })
        tack = time.time()
    print("Training Time: " + str(tack - tick))
示例#8
0
文件: Irc.py 项目: Extrememist/Doger
def on_SIGHUP(signum, frame):
	cmd = Commands.commands.get("admin")
	if cmd and Config.config.get("irclog"):
		Logger.irclog("Received SIGHUP, reloading Config")
		req = Hooks.Request(Config.config["irclog"][0], Config.config["irclog"][1], "@SIGHUP", "SIGHUP")
		Hooks.run_command(cmd, req, ["reload", "Config"])
示例#9
0
 def run(self):
     import Hooks
     Hooks.ChildStart()
     SocketMan.run(self)
示例#10
0
def train(_):
    # Import data
    mnist = input_data.read_data_sets(FLAGS.data_dir, one_hot=True)
    #PlaceHolder for Images
    x = tf.placeholder(tf.float32, [None, 784])
    #PlaceHolder for Labels-OneHot Vector
    y_ = tf.placeholder(tf.float32, [None, 10])
    #Build the Deep Model
    y_conv, keep_prob = Deep.deepnn(x)
    #Define loss and optimizer
    global_step = tf.train.get_or_create_global_step()
    SummaryDictionary = {}
    with tf.name_scope('loss'):
        cross_entropy = tf.nn.softmax_cross_entropy_with_logits(labels=y_,
                                                                logits=y_conv)
    cross_entropy = tf.reduce_mean(cross_entropy)
    SummaryDictionary.update({'cross_entropy': cross_entropy})
    #Define Optimizer and global step
    with tf.name_scope('adam_optimizer'):
        Optimizer = tf.train.AdamOptimizer(1e-4)
        train_step = Optimizer.minimize(cross_entropy, global_step=global_step)
    #Define Metric
    with tf.name_scope('accuracy'):
        correct_prediction = tf.equal(tf.argmax(y_conv, 1), tf.argmax(y_, 1))
        correct_prediction = tf.cast(correct_prediction, tf.float32)
    accuracy = tf.reduce_mean(correct_prediction)
    SummaryDictionary.update({'AccuracyMetric': accuracy})

    #Added Summaries for TensorBoard Visualization.
    ListOfSummaries = []
    for key in SummaryDictionary:
        ListOfSummaries.append(tf.summary.scalar(key, SummaryDictionary[key]))
    #for key, value in (SummaryDictionary).iteritems():
    #	ListOfSummaries.append(tf.summary.scalar(key,value))
    MergedSummaryOperation = tf.summary.merge(ListOfSummaries)

    BatchSize = FLAGS.batch_size
    SummarySteps = 100
    hooks = []
    #Get a sub set of the training DataSet for validation purpouses during Training
    #Get training subset for validation
    TrainingLenght = mnist.train.images.shape[0]
    #idx=np.random.randint(TrainingLenght,size=int(TrainingLenght/10))
    idx = np.random.randint(TrainingLenght, size=BatchSize)
    TrainingImagesValidation = mnist.train.images[idx]
    #print(TrainingImagesValidation.shape)
    TrainingLabelsValidation = mnist.train.labels[idx]
    #print(TrainingLabelsValidation.shape)

    #Create Hooks for saving summaries or Logging
    hooks.append(
        HOOKS.NewSummarySaverHook(MergedSummaryOperation,
                                  FLAGS.model_dir,
                                  SummarySteps,
                                  FLAGS.Iterations,
                                  features=x,
                                  labels=y_,
                                  dropout=keep_prob,
                                  batchx=TrainingImagesValidation,
                                  batchy=TrainingLabelsValidation,
                                  dropout_value=1.0))
    """
	hooks.append(HOOKS.FinalSummaryHook(SummaryDictionary,x, y_, keep_prob, mnist.train.images, mnist.train.labels, 1.0, FLAGS.Iterations,"Training"))
	hooks.append(HOOKS.NewSummarySaverHook(MergedSummaryOperation, FLAGS.model_dir+"/Testing", SummarySteps, FLAGS.Iterations,
		features=x,labels=y_,dropout=keep_prob,batchx=mnist.test.images, batchy=mnist.test.labels, dropout_value=1.0)
	)
	"""
    hooks.append(
        HOOKS.FinalSummaryHook(SummaryDictionary, x, y_, keep_prob,
                               mnist.test.images, mnist.test.labels, 1.0,
                               FLAGS.Iterations, "Testing"))

    tick = time.time()
    hooks.append(tf.train.StopAtStepHook(last_step=FLAGS.Iterations))
    with tf.train.MonitoredTrainingSession(master="",
                                           is_chief=True,
                                           hooks=hooks,
                                           checkpoint_dir=FLAGS.model_dir,
                                           save_checkpoint_secs=None,
                                           save_summaries_steps=None) as sess:
        step = sess.run(global_step)
        while not sess.should_stop():  #and step < FLAGS.Iterations:
            batch = mnist.train.next_batch(BatchSize)
            _, step = sess.run([train_step, global_step],
                               feed_dict={
                                   x: batch[0],
                                   y_: batch[1],
                                   keep_prob: 0.5
                               })
            tack = time.time()
    print("Training Time: " + str(tack - tick))