def load_script(self, fullname):
        self.logger.debug('trying "%s"', fullname)

        section = None
        settings = self.master.settings
        actions = MyData()
        try:
            with open(fullname, 'r') as r:
                # for each none empty line (removing the \n at the end)
                for ind, line in ((ind, line.rstrip())
                                  for ind, line in enumerate(r)
                                  if line.rstrip()):
                    # switch mode?
                    if line == '# settings':
                        section = 'settings'
                    elif line == '# actions':
                        section = 'actions'
                    else:
                        # handle json
                        d = json.loads(line)
                        if section == 'settings': settings.update(d)
                        if section == 'actions':
                            if ('name' in d and 'pressed' in d and 'time' in d
                                    and 'type' in d):
                                actions.append(d)
                            else:
                                raise KeyError(
                                    'missing an action key at line ' +
                                    (ind + 1) + ': name, pressed, time, type')
        except IOError as e:
            self.logger.warning('IOError! %r', e)
            messagebox.showwarning('IO Error',
                                   'Unable to load file, {0!r}'.format(e))
        except KeyError as e:
            self.logger.warning('KeyError! %r', e)
            messagebox.showwarning('Parsing Error',
                                   'Unable to load file, {0!r}'.format(e))
        except Exception as e:  #pylint: disable=broad-except
            self.logger.warning('error! %r', e)
            messagebox.showwarning(
                'Unhandled Exception',
                'Unable to load file, {0}.\n{1}'.format(fullname, e))
        else:
            self.logger.info('file loaded %d actions', len(actions))
            # success - make current
            self.master.settings.update(settings)
            self.master.actions = actions
            self._set_fullname(fullname)  # track filename used
            # inform user
            messagebox.showinfo('File loaded',
                                'script loaded, {0}.'.format(fullname))
    def start_recording(self, evt=None):  #@UnusedVariable #pylint: disable=unused-argument
        """start recording actions"""
        if not self.start_state(State.RECORDING):
            self.logger.warning('tried to start recording while %s!',
                                self.get_state())
            return  # stop!

        self.logger.info('start recording by %s ...',
                         'shortcut' if evt else 'click')

        # prompt for settings
        dlg = MySettingsDialog(parent=self, inputs=self.master.settings)
        if dlg.result is None:
            self.end_state(State.RECORDING)
            return  # dialog was dismissed
        else:
            self.master.settings.update(dlg.result)

        # format and prep
        self.btn_record.config(
            text=' '.join(['Stop'] + self.btn_record['text'].split(' ')[1:]))
        self.btn_run.config(state=tk.DISABLED)
        #self.set_next_action('',to_log=False)
        self.master.set_status('Recorder Active')

        # --- start recorder
        # clear console
        for item_id in self.list_ids:
            self.list_actions.delete(item_id)
        self.list_ids = list()
        # re-set list of actions
        self.master.actions = MyData()
        # create recorder queue
        self.actions_queue = queue.Queue()
        # create and start recorder
        self.actioner = MyRecorder(root=self, actions_queue=self.actions_queue)
        self.actioner.start()
        # monitor the queue
        self.after(100, self.handle_record_action)
Exemple #3
0
import torch
import torch.nn as nn
from torch.utils.data import random_split, DataLoader
from torch.utils.tensorboard import SummaryWriter
from net import Net_1
from mydata import MyData

# tensorboard可视化
writer = SummaryWriter('logs')

# 构建数据集
all_data = MyData(True)
all_size = len(all_data)
train_size = int(0.8 * all_size)
test_size = all_size - train_size
train_dataset, test_dataset = random_split(all_data, [train_size, test_size])

train_dataloader = DataLoader(train_dataset, batch_size=32, shuffle=True)
test_dataloader = DataLoader(test_dataset, batch_size=32, shuffle=True)

# 设置训练设备
device = torch.device('cuda')

# 构建神经网络实例
net = Net_1()
# net = torch.load('.pth')
net.to(device)

# 定义损失函数
loss_func = nn.CrossEntropyLoss()
loss_func.to(device)
        if kind != pyndn.UPCALL_INTEREST:
            log.warn("get kind: %s" % str(kind))
            return pyndn.RESULT_OK
        co = self.prepare(upcallInfo)
        self.handle.put(co)
        log.info("content: %s" % co)

        return pyndn.RESULT_INTEREST_CONSUMED

    def stop(self):
        #self.mydata.list_info()
        self.handle.setRunTimeout(DEFAULT_RUN_TIMEOUT / 100)
        return


mydata = MyData()


def signal_handler(signal, frame):
    print 'You pressed Ctrl+C!'

    mydata.list_info()
    sys.exit(0)


def usage():
    s = '''
        python consumer <NAME> [INTEREST_SCHEMA:-i|s|e] [MOD:-a|-na] [DEFAULT_BLOCK_SIZE: -b DEFAULT_BLOCK_SIZE]
        e.g.: python consumer.py /swordguy/chunksize/a -i -na -b 4096
            ------------------------------------------------------------
            Usage:
Exemple #5
0
"""
run.py

MyData can be launched by running "python run.py"
assuming that the Python module dependencies
have been installed, see:
requirements.txt
requirements-windows.txt

Only the very latest pre-release wxPython (3.0.3.dev)
is pip-installable.  For earlier versions (2.9.5 or
3.0.2), use the installer from http://wxpython.org
"""
import sys
from mydata import MyData

MyData.Run(sys.argv)
Exemple #6
0
import sys

from mydata import MyData

MyData.main(sys.argv)
Exemple #7
0
import torch
from mydata import MyData
from torch.utils.data.dataloader import DataLoader
from torch.utils.tensorboard import SummaryWriter

# tensorboard可视化
writer = SummaryWriter('logs_net_')

# 构建测试数据集
test_data =  MyData(False)
test_size = len(test_data)
test_dataloader = DataLoader(test_data, batch_size=32, shuffle=True)

# 设置测试设备
device = torch.device('cuda')

for i in range(5, 55, 5):
    # 导入已训练好的模型
    model = torch.load('net_1_model\\net_1_{}.pth'.format(i))
    model.to(device)

    # 测试步骤
    total_accuracy = 0

    model.eval()
    with torch.no_grad():
        for inputs, targets in test_dataloader:
            inputs = inputs.to(device)
            targets = targets.to(device)

            outputs = model(inputs)
            Interest Schema: default -i
            -i:    use id directly in the Interest, e.g.: <name>/0, <name>/0
            -e:    use exclusion in the Interest, e.g.: <name> with exclusion <0,1,2>
            -s:    use segment in the Interest, e.g.: <name>/%FD00
            
            Mod: default -na
            -a:    adapt expected optimal block size according to loss rate
            -na:   non-adaptive, use static block size
            
            DEFAULT_BLOCK_SIZE: default 4096
            -b DEFAULT_BLOCK_SIZE: set the default block size to DEFAULT_BLOCK_SIZE
           ----------------------------------------------------------------- 
        '''
    print s

mydata = MyData()

def signal_handler(signal, frame):
        print 'You pressed Ctrl+C!'
        global mydata
        mydata.list_info()
        sys.exit(0)
        
if __name__ == "__main__":
    if len(sys.argv) < 2 or sys.argv[1].startswith("-"):
        usage()
        exit(0)
    
    
    name = sys.argv[1]
    interest_schema = "id"
            return pyndn.RESULT_OK
        co = self.prepare(upcallInfo)
        self.handle.put(co)
        log.info("content: %s" %co)
        
        
        
        
        return pyndn.RESULT_INTEREST_CONSUMED

    def stop(self):
        #self.mydata.list_info()
        self.handle.setRunTimeout(DEFAULT_RUN_TIMEOUT/100)
        return
    
mydata = MyData()

def signal_handler(signal, frame):
        print 'You pressed Ctrl+C!'
        
        mydata.list_info()
        sys.exit(0)
        
def usage():
    s = '''
        python consumer <NAME> [INTEREST_SCHEMA:-i|s|e] [MOD:-a|-na] [DEFAULT_BLOCK_SIZE: -b DEFAULT_BLOCK_SIZE]
        e.g.: python consumer.py /swordguy/chunksize/a -i -na -b 4096
            ------------------------------------------------------------
            Usage:
            -h:    show help information