def f(input, params, stats, mode, prefix=''): x = F.conv2d(input, params[prefix + 'conv0'], padding=1) g0 = group(x, params, stats, prefix + 'group0', mode, 1) g1 = group(g0, params, stats, prefix + 'group1', mode, 2) g2 = group(g1, params, stats, prefix + 'group2', mode, 2) o = F.relu(batch_norm(g2, params, stats, prefix + 'bn', mode)) o = F.avg_pool2d(o, 8, 1, 0) o = o.view(o.size(0), -1) o = F.linear(o, params[prefix + 'fc.weight'], params[prefix + 'fc.bias']) #x_s = F.conv2d(input, params[prefix+'conv0_s'], padding=1) if stu_depth != 0: if opt.param_share: gs0 = group_student(x, params, stats, prefix + 'group0', mode, 1, n_s) gs1 = group_student(gs0, params, stats, prefix + 'group1', mode, 2, n_s) gs2 = group_student(gs1, params, stats, prefix + 'group2', mode, 2, n_s) else: gs0 = group_student(x, params, stats, prefix + 'groups0', mode, 1, n_s) gs1 = group_student(gs0, params, stats, prefix + 'groups1', mode, 2, n_s) gs2 = group_student(gs1, params, stats, prefix + 'groups2', mode, 2, n_s) os = F.relu(batch_norm(gs2, params, stats, prefix + 'bns', mode)) os = F.avg_pool2d(os, 8, 1, 0) os = os.view(os.size(0), -1) os = F.linear(os, params[prefix + 'fcs.weight'], params[prefix + 'fcs.bias']) return os, o, [g0, g1, g2, gs0, gs1, gs2] else: return o, [g0, g1, g2]
def rm(self): files = [] op = '' true_ops = ['-r', '-R', '--recursive'] for i in range(1, len(self.sliced_cmd)): x = self.sliced_cmd[i] if x in true_ops: if op == '': if len(x) > 2: op = x[1:3].lower else: op = x else: raise Exception('Invalid command.') else: files.append(x) if op == '': for i in files: if os.size(i) != 0: raise Exception( 'Cannot remove {}. File not empty'.format(i)) else: os.remove(i) else: for i in files: try: os.remove(i) except Exception: raise Exception('File does not exist')
def ls(self): ops = [] true_ops = ['-a', '--all', '-l', '--long'] for i in range(1, len(self.sliced_cmd)): x = self.sliced_cmd[i] if x in true_ops and x not in ops: if len(x) > 2: x = x[1:3] ops.append(x) else: raise Exception('Invalid command.') if len(ops) == 0: #open('.hello.txt', 'w') res = os.listdir() for i in range(0, len(res)): aux = res.pop() if (aux[0] != '.'): print(aux) #os.remove('.hello.txt') return elif '-a' in ops and '-l' in ops: #open('.nanana.txt', 'w') res = os.listdir() for i in range(0, len(res)): aux = res.pop() print("{} {}".format(os.size(aux), aux)) #os.remove('.nanana.txt') return elif '-a' in ops: #open('.hello.txt', 'w') res = os.listdir() for i in range(0, len(res)): aux = res.pop() print(aux) #os.remove('.hello.txt') return # -l else: #open('.hello.txt', 'w') res = os.listdir() for i in range(0, len(res)): aux = res.pop() if (aux[0] != '.'): print("{} {}".format(os.size(aux), aux)) #os.remove('.hello.txt') return
def main(): from argparse import ArgumentParser from os import makedirs, get_terminal_size as size from os.path import exists parser = ArgumentParser() parser.add_argument("path") parser.add_argument("-o", "--out", required = False) parser.add_argument("--width", type = int, required = False) parser.add_argument("--height", type = int, required = False) args = parser.parse_args() path = args.path out = args.out or "output" if not exists(out): makedirs(out) width = args.width or size().columns height = args.height or size().lines convert(path, out, width, height)
def main(): from log import log log.info("start main proccess and importing") from generator import convert from sound import Audio, getaudio from argparse import ArgumentParser from os import system, listdir, makedirs, get_terminal_size as size from os.path import exists, join log.info("imported") log.info("parsing arguments...") parser = ArgumentParser() parser.add_argument("path") parser.add_argument("-o", "--out", required=False) parser.add_argument("--width", type=int, required=False) parser.add_argument("--height", type=int, required=False) args = parser.parse_args() log.info("parsed") path = args.path out = args.out or "output" if not exists(out): makedirs(out) else: log.warning("output path is existing. text files will be overwritten.") log.info("set width and height of output...") width = args.width or size().columns height = args.height or size().lines log.info("start convert proccess") details = convert(path, out, width, height, log) fps = details["fps"] log.info("extracting audio...") getaudio(path, join(out, "sound.mp3"), log) log.info("extracted. make Audio object") audio = Audio(join(out, "sound.mp3")) log.info("start sound player and texts reader proccess...") audio.start() system(f"go run reader.go {fps} {out}")
def collate_fn(data): """Creates mini-batch tensors from the list of tuples (image, caption, objs_attrs). We should build custom collate_fn rather than using default collate_fn, because merging caption (including padding) is not supported in default. Args: data: list of tuple (image, caption, objs_attrs). - image: torch tensor of shape (3, 256, 256). - caption: torch tensor of shape (?); variable length. Returns: images: torch tensor of shape (batch_size, 3, 256, 256). targets: torch tensor of shape (batch_size, padded_length). lengths: list; valid length for each padded caption. """ # Sort a data list by caption length (descending order). data.sort(key=lambda x: len(x[1]), reverse=True) images, captions, objects_squares = zip(*data) # Merge images (from tuple of 3D tensor to 4D tensor). images = torch.stack(images, 0) # Merge captions (from tuple of 1D tensor to 2D tensor). lengths = [len(cap) for cap in captions] targets = torch.zeros(len(captions), max(lengths)).long() for i, cap in enumerate(captions): end = lengths[i] targets[i, :end] = cap[:end] objects_squares_lengths = [ os.size(0) if os is not None else 0 for os in objects_squares ] objects_squares = torch.cat( [os for os in objects_squares if os is not None], 0) return images, targets, lengths, objects_squares, objects_squares_lengths
if button_a.is_pressed() and running is False: sleep(250) running = True counter = 0 display.show(Image.ANGRY, wait=False) start_time = running_time() if running is True and running_time() - start_time > dur: end_time = running_time() running = False display.show(Image.HAPPY, wait=False) #now write the data out to a file count = len(os.listdir()) #with open("data_{}.dat".format(count+1), mode='wt') as f: with open("data_{}.dat".format(count + 1), 'wt') as f: for d in data: f.write(str(d) + "\n") data = [] if button_b.was_pressed() and running is False: files = os.listdir() for f in files: print("{f} - {s}".format(f=f, s=os.size(f))) if running: if running_time() - last_sent > period: last_sent = running_time() data.append(accelerometer.get_values()) counter = counter + 1
from microbit import * import music import neopixel import radio import speech import os panic(5) sleep(30) rt = running_time() display.clear() display.show(Image.ANGRY) display.set_pixel() uart.read(5) i2c.read(4, 3, True) compass.calibrate() button_a.is_pressed() button_b.is_pressed() pin0.read_analog() display.scroll('test') z = temperature() os.size() neopixel.clear() music.play(music.BA_DING,pin0) radio.config(length=5) speech.say("I am a little robot", speed=92, pitch=60, throat=190, mouth=190) music.play(music.BA_DING,)