def piSetUp(): GPIO.setmode(GPIO.BOARD) TIC1 = TIC() TIC1.TICstart() motorL = motor("left", [32, 31, 33]) encoderA = encoder("left", [26, 29], 50, motorL) motorR = motor("right", [35, 36, 37]) encoderB = encoder("left", [38, 40], 50, motorR) proxSensA= psensor("Front",[16,18], 50) proxSensB= psensor("Left",[12,22], 35) proxSensC= psensor("Right",[7,13], 35) rob = robot(motorL, motorR, encoderA, encoderB, proxSensA, proxSensB, proxSensC) rob.pinSetup() tnow = time.time() rob.obsDetect() while(1): rob.run() TIC1.run()
def eval_arbitrary(content_path, style_path, output_path, height=560, width=800): # content_name = '002.jpg' # style_name = 'style2.jpg' # content_path = 'content_test/' + content_name # style_path = 'style_test/' + style_name content_image = preprocessing.get_resized_image(content_path, height, width) style_image = preprocessing.get_resized_image(style_path, height, width) content_model = encoder.encoder(content_image - loss.MEAN_PIXELS) style_model = encoder.encoder(style_image - loss.MEAN_PIXELS) content_maps = content_model['relu4_1'] style_maps = style_model['relu4_1'] fusion_maps = AdaIN.adaIn(content_maps, style_maps) generated_batches = decoder.decoder(fusion_maps) + loss.MEAN_PIXELS saver = tf.train.Saver() with tf.Session() as sess: ckpt = tf.train.get_checkpoint_state('save/') if ckpt and ckpt.model_checkpoint_path: saver.restore(sess, ckpt.model_checkpoint_path) res = sess.run(generated_batches) preprocessing.save_image(output_path, res)
def binarize_encode(dat, dat_valid): binarizer = True b = encoder.encoder() dat = b.binarize_scale(df=dat, NA=-1, binarizer=binarizer) c = encoder.encoder() dat_valid = c.binarize_scale(df=dat_valid, NA=-1, binarizer=binarizer) print( "Data contains {0} categorical, {1} numerical and {2} binary features". format(len(b.categorical), len(b.numeric), len(b.binary))) print( "Validation data contains {0} categorical, {1} numerical and {2} binary\ features".format(len(c.categorical), len(c.numeric), len(c.binary)))
def multiGraph(u_feature, i_feature, u_neighs, i_neighs, u_adj, i_adj, embed_dim, droprate=0.5, weight_decay=0.0005, device="cpu"): u_embed = multi_graph(u_feature.to(device), u_neighs, embed_dim, device=device, weight_decay=weight_decay) i_embed = multi_graph(i_feature.to(device), i_neighs, embed_dim, device=device, weight_decay=weight_decay) # user part u_agg_embed_cmp1 = aggregator(u_feature.to(device), i_feature.to(device), u_adj, embed_dim, droprate=droprate, device=device, weight_decay=weight_decay) u_embed_cmp1 = encoder(embed_dim, u_agg_embed_cmp1, u_embed, device=device) u_embed = cmp_combiner(u_embed_cmp1, embed_dim, droprate, device=device) # item part i_agg_embed_cmp1 = aggregator(u_feature.to(device), i_feature.to(device), i_adj, embed_dim, droprate=droprate, is_user_part=False, device=device, weight_decay=weight_decay) i_embed_cmp1 = encoder(embed_dim, i_agg_embed_cmp1, i_embed, is_user_part=False, device=device) i_embed = cmp_combiner(i_embed_cmp1, embed_dim, droprate, device=device) return u_embed, i_embed
def __init__(self): # ---------- SETTINGS ---------- # self.MIN_CYCLE_PERIOD = 10 # Minimum time (in ms) between program iterations # -------- PORT MAPPING -------- # self.RED_LED_PORT = 28 # GP28 Pin 34 self.GREEN_LED_PORT = 27 # GP27 Pin 32 self.BUZZER_PORT = 22 # GP22 Pin 29 self.WHEEL_1_PORT = 8 # GP8 Pin 11 self.WHEEL_2_PORT = 12 # GP12 Pin 16 self.WHEEL_3_PORT = 14 # GP14 Pin 19 self.ENC_1A_PORT = 2 # GP2 Pin 4 self.ENC_1B_PORT = 3 # GP3 Pin 5 self.ENC_2A_PORT = 4 # GP4 Pin 6 self.ENC_2B_PORT = 5 # GP5 Pin 7 self.ENC_3A_PORT = 6 # GP6 Pin 9 self.ENC_3B_PORT = 7 # GP7 Pin 10 self.I2C_SDA = 0 # GP0 Pin 1 self.I2C_SCL = 1 # GP1 Pin 2 # ------------ VARS ------------ # self.enabled = False self.connected = False self.i2caddr = 0x0 self.sqrt3 = 3**0.5 / 2 # Finding square roots (and division) is time consuming. Let's only do it once # --------- INITIALIZE --------- # self.red_led = machine.Pin(self.RED_LED_PORT, machine.Pin.OUT) self.red_led.value(0) self.green_led = machine.Pin(self.GREEN_LED_PORT, machine.Pin.OUT) self.green_led.value(0) self.buzzer = machine.Pin(self.BUZZER_PORT, machine.Pin.OUT) self.buzzer.value(0) self.wheel1 = motor(self.WHEEL_1_PORT) self.wheel2 = motor(self.WHEEL_2_PORT) self.wheel3 = motor(self.WHEEL_3_PORT) self.encoder1 = encoder(self.ENC_1A_PORT, self.ENC_1B_PORT) self.encoder2 = encoder(self.ENC_2A_PORT, self.ENC_2B_PORT) self.encoder3 = encoder(self.ENC_3A_PORT, self.ENC_3B_PORT) self.kiwi_encoder = kiwi_encoders(self.encoder1, self.encoder2, self.encoder3) sda = machine.Pin(self.I2C_SDA) scl = machine.Pin(self.I2C_SCL) self.i2c = machine.I2C(0, sda=sda, scl=scl, freq=400000) self.wdt = None
def __init__(self, threshold_1 = 3e-06, threshold_2 = 6.0e-5, path = './face_recognition/saved_model/beta', name = 'alpha'): self.threshold1 = tf.constant(threshold_1) self.threshold2 = tf.constant(threshold_2) self.input = tf.placeholder(tf.int32) self.encoder = encoder.encoder(self.input, name) self.centroid = None self.path = path
def get_conf(self, conf_file): conf_parse = ConfigParser.ConfigParser() conf_parse.read(conf_file) self.password_file = conf_parse.get("upload", "PW_PATH") self.REDIS_HOST = conf_parse.get("listener", "REDIS_HOST") self.REDIS_PORT = conf_parse.getint("listener", "REDIS_PORT") self.REDIS_DB = conf_parse.getint("listener", "REDIS_DB") self.REDIS_AUTH = conf_parse.get("listener", "REDIS_AUTH") self.PRIVATE_KEY_FILE = conf_parse.get("listener", "PRIVATE_KEY_FILE") self.REMOTE_KEY_FILE = conf_parse.get("listener", "REMOTE_KEY_FILE") self.encode = encoder.encoder(self.PRIVATE_KEY_FILE, self.REMOTE_KEY_FILE) server_define = conf_parse.get("upload", "SERVER_DEFINE") self.max_expire = {} for s in server_define.split(','): s = s.strip() expire = conf_parse.get("upload", "%s_max_expire" % s) path = conf_parse.get("upload", "%s_PATH" % s) servers = set() try: for h in open(path, 'r'): host = h.strip() if host.startswith('#') or host == '': continue servers.add(host) except Exception, e: print >> sys.stderr, e sys.exit(1) self.max_expire[s] = {"max_expire": expire, "hosts": servers}
def __init__(self, encoder_path, decoder_path=None): super(net_train, self).__init__() self.encoder = encoder(encoder_path) self.decoder = decoder() self.decoder.load_state_dict(torch.load( decoder_path)) #Need to change this to be done in encoder self.mse_loss = nn.MSELoss()
def modelo(train_X, valid_X, train_ground, valid_ground, data): number_of_layers, filter_size, number_of_filters, epochs, batch_size = parametroi.parameters( ) print( '//////////////////////////////////////////////////////////////////////////////////////////////' ) inChannel = 1 x, y = 28, 28 input_img = Input(shape=(x, y, inChannel)) conv, enc_layers = encoder.encoder(input_img, filter_size, number_of_filters, number_of_layers) decoded = decoder.decoder(conv, filter_size, number_of_filters, enc_layers, number_of_layers) autoencoder = Model(input_img, decoded) autoencoder.compile(loss='mean_squared_error', optimizer=RMSprop()) model = autoencoder.fit(train_X, train_ground, batch_size=batch_size, epochs=epochs, verbose=1, validation_data=(valid_X, valid_ground)) return model, epochs, autoencoder
def classify(self, testSet, attributes, labels, onehot=False): #In order to classify, we use predict given the test set. #X is a 2D array of the encodings of the testSet, and the list of attributes. decrypt = encoder.encoder() confusionMatrix = [ [0] * len(labels) for _ in range(len(labels)) ] #This is a 2D array, with dimensions: number of labels x number of labels. results = [] #This array stores the predictions in encoding form. testEncodings, testLabels = decrypt.encode(testSet, attributes) if not onehot: testEncodings = [] att = copy.deepcopy(attributes) att.pop('label') for instance in testSet: testEncodings.append([float(instance[a]) for a in att]) results = self.mlp.predict(testEncodings) #Now, we start a counter. We use the counter as the index of both testSetEncodings and results. #Then, we go through and find the index of the 1 in each of them. Use those as the #coordinates in confusionMatrix. counter = 0 while counter < len(testEncodings): x = numpy.argmax(testLabels[counter]) y = int(results[counter]) confusionMatrix[x][y] = confusionMatrix[x][y] + 1 counter = counter + 1 """file = open(filename,'w') - turns out I don't actually need the file stuff for y in confusionMatrix: for x in confusionMatrix[y]: file.write(confusionMatrix[x][y]) file.write('\n')""" return confusionMatrix, self.mlp.score( testEncodings, numpy.argmax(testLabels, axis=1))
def __init__(self, trained_model_path='./saved_model/alpha', name='alpha'): self.input = tf.placeholder(tf.int32) self.encoder = encoder.encoder(self.input, name) self.learning_rate = tf.placeholder(tf.float32) self.labels = tf.placeholder(tf.int32) self.densenet = densenet.densenet(self.encoder, name) self.trainable_vars = self.densenet.get_var_list() self.output = self.densenet.output self.loss = tf.reduce_mean( tf.nn.sigmoid_cross_entropy_with_logits( logits=self.densenet.denseoutput4, labels=tf.cast(self.labels, tf.float32) / 255.0)) self.session = tf.Session() self.output_verdict = tf.cast((self.output >= 0.5), tf.int32) self.correct = tf.equal(self.output_verdict, self.labels) self.accuracy = tf.reduce_mean(tf.cast(self.correct, dtype=tf.float32)) self.train = tf.train.GradientDescentOptimizer( self.learning_rate).minimize(self.loss, var_list=[self.trainable_vars]) if trained_model_path is None: self.session.run(tf.global_variables_initializer()) else: self.session.run(tf.global_variables_initializer()) saver = tf.train.Saver() saver.restore(self.session, trained_model_path)
def vae_bernoulli_overall_precision(path_model='models/bernoulli/vae/model', num_batches=10): threshold = 0.5 from encoder import encoder _search = search( encoder(filename_meta_graph='models/bernoulli/encoder/model', path_model=path_model, input_name='x', output_name='encoder_softmax')) from mnist import mnist _mnist = mnist() points_binary = _search.load_codes_from_file( os.path.join(os.path.dirname(path_model), 'codes.binary')) points_real = _search.load_codes_from_file( os.path.join(os.path.dirname(path_model), 'codes.real')) print( 'binary: ', _search.compute_overall_precision(_mnist.test, points_binary, 100, binary=True, batch_size=100, threshold=threshold, num_batches=num_batches)) _mnist = mnist() print( 'real: ', _search.compute_overall_precision(_mnist.test, points_real, 100, binary=False, batch_size=100, threshold=threshold, num_batches=num_batches))
def __init__(self, path='./face_recognition/saved_model/beta', name='alpha'): self.input = tf.placeholder(tf.int32) self.encoder = encoder.encoder(self.input, name) self.output = self.encoder.embedding self.path = path
def train(self, trainingSet, attributes, hidden_layer_sizes, num_training_iterations, seed, onehot=False): #In order to fit a training set, we need to pass in an array of #the encodings of the training set and the number of attributes? #As well as the list of all labels. encrypt = encoder.encoder() if onehot: encodings, vectors = encrypt.encode(trainingSet, attributes) else: encodings = [] att = copy.deepcopy(attributes) att.pop('label') for instance in trainingSet: encodings.append([float(instance[a]) for a in att]) _, vectors = encrypt.encode(trainingSet, attributes) self.mlp = MLPClassifier(hidden_layer_sizes=hidden_layer_sizes, solver='sgd', batch_size=len(trainingSet), max_iter=num_training_iterations, random_state=1, momentum=0) #X is a 2D array of the encodings of the trainingSet, and the list of attributes. labels = [] for i in range(len(vectors)): labels = numpy.append(labels, numpy.argmax(vectors[i])) self.mlp.fit(encodings, labels)
def par_test(): print "Number of active threads before starting: " + str( threading.activeCount()) print "Active threads before starting: " + str(threading.enumerate()) pi = pigpio.pi() sonar_queue = Queue.Queue() encoder_queue = Queue.Queue() sonar = ranger(pi=pi, trigger=17, echo=27, queue=sonar_queue) enc = encoder(pi=pi, signal_pin=2, queue=encoder_queue) motor_left = motor(pi=pi, forward_pin=26, back_pin=19) motor_right = motor(pi=pi, forward_pin=16, back_pin=20) car = Car(pi=pi, motor_left=motor_left, motor_right=motor_right, encoder_left=enc, encoder_right=enc, sonar=sonar, encoder_queue=encoder_queue, sonar_queue=sonar_queue) result = car.parallel_test() print "Counts: " + str(result[0]) print "Sonar Readings: " + str(result[1]) print "Encoder Readings: " + str(result[2]) car.cleanup()
def main(): # parse arguments args = parse_args() if args is None: exit() if args.benchmark_mode: torch.backends.cudnn.benchmark = True # declare instance for GAN if args.gan_type == 'RankCGAN': gan = RankCGAN(args) elif args.gan_type == 'RankCGAN_2D': gan = RankCGAN_2D(args) elif args.gan_type == 'encoder': gan = encoder(args) gan.load() else: print('Model type is not defined') # launch the graph in a session gan.train() print(" [*] Training finished!") # visualize learned generator gan.visualize_results(args.epoch) print(" [*] Testing finished!")
def __init__(self, num_classes=10, level=15): train_data = [] train_labels = [] self.encoder = encoder(level=level) # if not os.path.exists("cifar-10-batches-bin"): # urllib.request.urlretrieve("https://www.cs.toronto.edu/~kriz/cifar-10-binary.tar.gz", # "cifar-data.tar.gz") # os.popen("tar -xzf cifar-data.tar.gz").read() # for i in range(5): # r,s = load_batch("cifar-10-batches-bin/data_batch_"+str(i+1)+".bin") # train_data.extend(r) # train_labels.extend(s) (train_data, train_labels), (test_data, test_labels) = cifar10.load_data() train_data = train_data/255.0 test_data = test_data/255.0 train_labels = keras.utils.to_categorical(train_labels, num_classes) test_labels = keras.utils.to_categorical(test_labels, num_classes) self.test_data = test_data self.test_labels = test_labels VALIDATION_SIZE = 5000 self.validation_data = train_data[:VALIDATION_SIZE, :, :, :] self.validation_labels = train_labels[:VALIDATION_SIZE] self.train_data = train_data[VALIDATION_SIZE:, :, :, :] self.train_labels = train_labels[VALIDATION_SIZE:] train_data = np.transpose(self.train_data, axes=(0, 3, 1, 2)) channel0, channel1, channel2 = train_data[:, 0, :, :], train_data[:, 1, :, :], train_data[:, 2, :, :] channel0, channel1, channel2 = self.encoder.tempencoding(channel0), self.encoder.tempencoding( channel1), self.encoder.tempencoding( channel2) train_data = np.concatenate([channel0, channel1, channel2], axis=1) self.encoding_train_data = np.transpose(train_data, axes=(0, 2, 3, 1)) test_data = np.transpose(self.test_data, axes=(0, 3, 1, 2)) channel0, channel1, channel2 = test_data[:, 0, :, :], test_data[:, 1, :, :], test_data[:, 2, :, :] channel0, channel1, channel2 = self.encoder.tempencoding(channel0), self.encoder.tempencoding( channel1), self.encoder.tempencoding( channel2) test_data = np.concatenate([channel0, channel1, channel2], axis=1) self.encoding_test_data = np.transpose(test_data, axes=(0, 2, 3, 1)) validation_data = np.transpose(self.validation_data, axes=(0, 3, 1, 2)) channel0, channel1, channel2 = validation_data[:, 0, :, :], validation_data[:, 1, :, :], validation_data[:, 2, :, :] channel0, channel1, channel2 = self.encoder.tempencoding(channel0), self.encoder.tempencoding( channel1), self.encoder.tempencoding( channel2) validation_data = np.concatenate([channel0, channel1, channel2], axis=1) self.encoding_validation_data = np.transpose(validation_data, axes=(0, 2, 3, 1)) self.train_data -= 0.5 self.test_data -= 0.5 self.validation_data -= 0.5
def __get_conf__(self, conf_file): conf_parse = ConfigParser.ConfigParser() conf_parse.read(conf_file) self.SERVER_HOST = conf_parse.get("uploader", "SERVER_HOST") self.SERVER_PORT = conf_parse.getint("uploader", "SERVER_PORT") self.PUBLIC_KEY_FILE = conf_parse.get("whisperer", "PUBLIC_KEY_FILE") self.PRIVATE_KEY_FILE = conf_parse.get("whisperer", "PRIVATE_KEY_FILE") self.REMOTE_KEY_FILE = conf_parse.get("whisperer", "REMOTE_KEY_FILE") self.encode = encoder.encoder(self.PRIVATE_KEY_FILE, self.REMOTE_KEY_FILE)
def straightRun(): GPIO.setmode(GPIO.BOARD) motorL = motor("left", [32, 31, 33]) encoderA = encoder("left", [26, 29], 50, motorL) motorR = motor("right", [35, 36, 37]) encoderB = encoder("left", [38, 40], 50, motorR) proxSensA= psensor("Front",[16,18], 50) proxSensB= psensor("Left",[12,22], 35) proxSensC= psensor("Right",[7,13], 35) rob = robot(motorL, motorR, encoderA, encoderB, proxSensA, proxSensB, proxSensC) rob.pinSetup() while(1): rob.direct("forward", 50)
def autoencoder(image): with tf.variable_scope('autoencoder', reuse=tf.AUTO_REUSE): shapeEncoding, textureEncoding, cameraSetup = encoder(image) texture = decoder_texture(textureEncoding) shape = decoder_shape(shapeEncoding) return shape, texture, cameraSetup
def create_model(Tx, Ty, n_a, n_s, human, machine): x_input = keras.Input((Tx, len(human))) hidden = keras.Input((n_s,)) cell = keras.Input((n_s,)) # a [m, Tx, 2*n_a] a = encoder(n_a, x_input) # outputs [Ty, m, len(machine_vocab)] outputs = decoder(Tx, Ty, n_s, machine, a, hidden, cell) # outputs = AttensionDecoder(Tx, Ty, n_s, machine)(a, hidden, cell) return keras.Model(inputs=[x_input, hidden, cell], outputs=outputs)
def EfficientConvNet(classes, inpHeight=360, inpWidth=480): img_input = Input(shape=(inpHeight, inpWidth, 3)) Effnet = encoder(img_input) Effnet = decoder(Effnet, classes) output = Model(img_input, Effnet).output_shape Effnet = (Reshape((output[1] * output[2], classes)))(Effnet) Effnet = Activation('softmax')(Effnet) model = Model(img_input, Effnet) model.outputWidth = output[2] model.outputHeight = output[1] return model
def main(): text = readFile("ciphers.txt")[0] encoded = encoder(text) key = encoded["key"] plainText = encoded["plain"] cipher = encoded["cipher"] keyMap = crack(cipher) # print(getUnfound(keyMap)) for key in keyMap: print(key + ": " + str(keyMap[key])) print(getInitGuess(keyMap))
def motorTest(): motorL = motor("left", [32, 31, 33]) encoderA = encoder("left", [26, 29], 50, motorL) motorL.pinSetup() encoderA.pinSetup() motorL.setVolt(55) tnow = time.time() while (tnow + 3 > time.time()): encoderA.RPMcalc()
def localize(event_list, event_time_list, config): estimated_pos_dict, evidence_map_dict = estimate_led_positions_kmeans( event_list, config['freq'], n_led=config['n_led'], t_at=config['t_at'], event_time_list=event_time_list, n_tol=1, sigma=30 ) encoded_msgs = encoder( event_list, estimated_pos_dict, config['freq'], config['thres_detect_led'], t_begin=0.0, t_end=config['t_at'] ) ps = np.zeros((2, 2)) if config['debug']: plt.imshow(np.zeros((720, 1280))) for key in encoded_msgs.keys(): pos = estimated_pos_dict[key] msg = encoded_msgs[key] print('pos:{0}, msg:{1}'.format([int(pos[0]), int(pos[1])], msg)) if msg == [True, True, False, False, True, True]: clr = 'yellow' label = 'yellow LED, Origin' ps[1] = pos elif msg == [True, True, True, True, False, False]: clr = 'red' label = 'red LED' ps[0] = pos else: clr = 'white' label = 'invalid' if config['debug']: plt.scatter(pos[0], pos[1], color=clr, label=label) if config['debug']: plt.legend() plt.show() K, dist = load_calibration() Pws = np.array(config['led_pos']) # [m?] R, T, ans = solve_pnp(ps, Pws, K, dist, method=config['method']) if config['method'] in ['xyz', 'xyzyaw']: update_ceres_input(ps, Pws, K, dist, ans) return R, T
def vae_gaussian_example(binary=True): from encoder import encoder _search = search( encoder(filename_meta_graph='models/gaussian/encoder/model', path_model='models/gaussian/vae/model', input_name='x', output_name='encoder_params')) from mnist import mnist _mnist = mnist() images, labels = _mnist.train.generate_samples(2) codes = _search.compute_codes(images, binary=binary) print(codes) print(_search.compute_distance_pairwise(codes[0], codes[1], binary=binary))
def get_conf(self, conf_file): conf_parse = ConfigParser.ConfigParser() conf_parse.read(conf_file) self.BIND_IP = conf_parse.get("listener", "BIND_IP") self.BIND_PORT = conf_parse.getint("listener", "BIND_PORT") self.REDIS_HOST = conf_parse.get("listener", "REDIS_HOST") self.REDIS_PORT = conf_parse.getint("listener", "REDIS_PORT") self.REDIS_DB = conf_parse.getint("listener", "REDIS_DB") self.REDIS_AUTH = conf_parse.get("listener", "REDIS_AUTH") self.PUBLIC_KEY_FILE = conf_parse.get("listener", "PUBLIC_KEY_FILE") self.PRIVATE_KEY_FILE = conf_parse.get("listener", "PRIVATE_KEY_FILE") self.REMOTE_KEY_FILE = conf_parse.get("listener", "REMOTE_KEY_FILE") self.LOG_LEVEL = conf_parse.get("listener", "LOG_LEVEL") self.encode = encoder.encoder(self.PRIVATE_KEY_FILE, self.REMOTE_KEY_FILE)
def calc(number): try: number = int(number) if number < 0: return 'We do not calculate negative numbers' return encoder(number) except: num = number for letter in ['I', 'V', 'X', 'L', 'C', 'D', 'M']: if letter in num: num = num.replace(letter, '') if len(num) != 0: return 'Wrong phrase' return str(decoder(number))
def cust(sock): global checklist time.sleep(0.2) sock.send("incust") time.sleep(0.2) checklist=pickle.loads(sock.recv(1024)) print checklist add_file=get_addr(checklist[8]) if checklist[0]=="yes": print("NOW ENCRYPTING...") f=open(add_file,"r") mg=f.readlines() f.close() var1="new_enc_"+checklist[8] f=open(var1,"w") for i in range(len(mg)): print(mg[i],i) rr=encoder.encoder(mg[i]) for k in range(len(rr)): if rr[k]!="\n": f.write(rr[k]) f.write("\n") print("done encoding text") f.close() checklist[8]=var1 update(var1) if checklist[1]=="yes": subprocess.call(['C:/ffmpeg/bin/ffmpeg.exe', '-i', checklist[8] , '-ss', checklist[4], '-t', checklist[5] , '-async', '1',"cut_"+checklist[8] ]) checklist[8]="cut_"+checklist[8] if checklist[3]=="yes": if checklist[9] == 3 or checklist[9]==4: subprocess.call(['C:/ffmpeg/bin/ffmpeg.exe', '-i', checklist[8], '-c:v', 'libx264', '-crf', '24', '-b:v', '1M', '-c:a', 'aac', 'low_'+checklist[8]]) else: image = Image.open(checklist[8]) image.save("low_"+checklist[8],quality=checklist[7],optimize=True) checklist[8]="low_"+checklist[8] if checklist[2]=="yes": new_filename=checklist[8]+".gz" with open(checklist[8], 'rb') as f_in, gzip.open(new_filename, 'wb') as f_out: shutil.copyfileobj(f_in, f_out) #NEW FILENAME SEND FROM HERE checklist[8]=new_filename update(checklist[8]) sock.send(pickle.dumps(checklist[8]))
def __init__(self, batch_size, is_training=True, save_step=50): self.logger = logging.getLogger(__name__) log_handler = logging.StreamHandler() log_formatter = logging.Formatter( '%(asctime)s - %(name)s: %(message)s') log_handler.setFormatter(log_formatter) self.logger.addHandler(log_handler) self.inputs = tf.placeholder(tf.int32, shape=[None, None]) self.mel_targets = tf.placeholder(tf.float32, shape=[None, None, hp.num_mels]) self.linear_targets = tf.placeholder( tf.float32, shape=[None, None, hp.num_freq / 2 + 1]) self._batch_size = batch_size self._is_training = is_training self._save_step = save_step with tf.device('/gpu:0'): self.embedding_variables = tf.get_variable( 'embedding', shape=[len(hp.symbols), 256]) self.embedding_inputs = tf.nn.embedding_lookup( self.embedding_variables, self.inputs) self.encoder_outputs = encoder(self.embedding_inputs, is_training=is_training) self.mel_outputs, self.linear_outputs = full_decoding( self.inputs, self.encoder_outputs, is_training, self.mel_targets, batch_size=batch_size) self.global_step = tf.Variable(0, name='global_step', trainable=False) self._loss() self._optimizer() self.sess = tf.Session(config=tf.ConfigProto( allow_soft_placement=True)) self.saver = tf.train.Saver() self.sess.run(tf.global_variables_initializer()) self._summary_graph() self._make_model_dir() self._load_model()
def upload(directory, filename): filename_full = os.path.abspath(os.path.join(directory, filename)) error_fullpath = os.path.abspath( os.path.join(os.path.dirname(__file__), error_dir)) # This is where we gather the upload data with open(filename_full, 'r') as f: d = json.load(f) assert d # This validates that we have something here assert isinstance(d, dict) # Validates that we have a dictionary name_kernel = strip_right(filename, '.json') d.update({'name': name_kernel}) d_string = json.dumps(d) print(type(d_string)) encoded = encoder(d_string, public_keyname) for i in encoded.keys(): current_type = type(encoded[i]) print(f"{i} type: {current_type}") try: req = requests.post(remote, json=encoded) print(req.status_code) if ( req.status_code == 200 ): #aka data was successfully recieved and interpreted without a problem if gpio_bool: upload_led.on() time.sleep(0.3) upload_led.off() os.remove(filename_full) return # We got rate limited - need to wait for next upload elif (req.status_code == 429): if gpio_bool: error_led.on() time.sleep(10) if gpio_bool: error_led.off() return else: return except ConnectionError: print('Server is down.') return
def vae_bernoulli_example(binary=True): from encoder import encoder _search = search( encoder(filename_meta_graph='models/bernoulli/encoder/model', path_model='models/bernoulli/vae/model', input_name='x', output_name='encoder_softmax')) from mnist import mnist _mnist = mnist() images, labels = _mnist.train.generate_samples(2) codes = _search.compute_codes(images, binary=binary) print(codes) print( _search.compute_distance_pairwise(codes[0], codes[1], binary=binary, threshold=threshold))
def vae_gaussian_compute_all_codes(binary=True, path_model='models/gaussian/vae/model'): from encoder import encoder _search = search( encoder(filename_meta_graph='models/gaussian/encoder/model', path_model=path_model, input_name='x', output_name='encoder_params')) if binary: file_name = os.path.join(os.path.dirname(path_model), 'codes.binary') else: file_name = os.path.join(os.path.dirname(path_model), 'codes.real') from mnist import mnist _mnist = mnist() codes, labels, images = _search.compute_all_codes(_mnist.train, binary=binary, file_name=file_name)
def get_conf(self, conf_file): conf_parse = ConfigParser.ConfigParser() conf_parse.read(conf_file) self.BIND_IP = conf_parse.get("upload", "BIND_IP") self.BIND_PORT = conf_parse.getint("upload", "BIND_PORT") self.password_file = conf_parse.get("upload", "PW_PATH") self.group_file = conf_parse.get("upload", "SERVER_GROUP_PATH") self.dev_file = conf_parse.get("upload", "DEV_GROUP_PATH") self.REDIS_HOST = conf_parse.get("listener", "REDIS_HOST") self.REDIS_PORT = conf_parse.getint("listener", "REDIS_PORT") self.REDIS_DB = conf_parse.getint("listener", "REDIS_DB") self.REDIS_AUTH = conf_parse.get("listener", "REDIS_AUTH") self.PRIVATE_KEY_FILE = conf_parse.get("listener", "PRIVATE_KEY_FILE") self.REMOTE_KEY_FILE = conf_parse.get("listener", "REMOTE_KEY_FILE") self.encode = encoder.encoder(self.PRIVATE_KEY_FILE, self.REMOTE_KEY_FILE) server_define = conf_parse.get("upload", "SERVER_DEFINE") ROOT = conf_parse.get("upload", "ROOT") self.ext_expire = self.timedelta(conf_parse.get("upload", "MAX_EXPIRE")) self.group_file = [ x.strip() for x in self.group_file.split(',')] self.max_expire = {} self.root = set() for u in ROOT.split(','): self.root.add(u.strip()) print "############ Root ############" print self.root print "############ Root ############" for s in server_define.split(','): s = s.strip() print "load server_define" + s expire = conf_parse.get("upload", "%s_max_expire" % s) path = conf_parse.get("upload", "%s_PATH" % s) servers = set() try: for h in open(path, 'r'): host = h.split('#')[0].strip() if host == '': continue servers.add(host) except Exception, e: print >> sys.stderr, e sys.exit(1) self.max_expire[s] = {"max_expire": expire, "hosts": servers}
def test_001_t (self): print '--- encoder - test_001_t\n' # create a data sink src=blocks.vector_source_i([0, 1, 0, 1, 0]) # create encoder enc = encoder() # create quantum channel q_ch = channel_ii() # create classical channel c_ch = channel_ii() # create decoder dec = decoder() # interconnections self.tb.connect((src,0), (enc,0)) self.tb.connect((enc,0), q_ch) self.tb.connect((enc,1), c_ch) self.tb.connect(q_ch, (dec,0)) self.tb.connect(c_ch, (dec,1)) self.tb.msg_connect(dec,"feedback",enc,"feedback") self.tb.msg_connect(enc,"ciphertext",dec,"ciphertext") self.tb.run()
import traceback from findmyiphone import findMyiPhone from encoder import encoder print "Content-type: application/json" print sys.stderr=sys.stdout try: credentials=cgi.FieldStorage() username=credentials.getvalue('u') password=credentials.getvalue('p') action=credentials.getvalue('action'); enc=encoder(password) db=anydbm.open("./loc.db","c") result=[] if action == "getHistory": for k, v in db.iteritems(): entry=enc.decode(v) if( "timeStamp" in entry ): result.append(json.loads(entry)) if action == "clearHistory": for k in db.keys(): del db[k] if action == "getLocation": #Check new location fmi=findMyiPhone(username, password) fmi.login()
def main(): encoder(sys.argv[1]) decoder(sys.argv[1])
with h5py.File(constants.train_packed_file, "r") as f: images = f.get("X") labels = f.get("Y") centroids, W, M, patches, Xcont, xZCAWhite =\ preprocess(images, labels, sels[5]) if verbose: draw_patches(patches[:36], H=patchSize, W=patchSize) draw_patches(Xcont[:36], H=patchSize, W=patchSize) draw_patches(xZCAWhite[:36], H=patchSize, W=patchSize) draw_patches(centroids[:600], H=patchSize, W=patchSize, br=1.0, cont=2) del Xcont, xZCAWhite, patches with h5py.File(constants.train_packed_file, 'r') as fi: images = fi.get('X') labels = fi.get('y') X = images y = labels with h5py.File(constants.train_features_file, 'w') as fo: XC1 = encoder(X, centroids, W, M, chunk_size=constants.chunk_size, batch_size=constants.batch_size, Y=y, fo=fo) with h5py.File(constants.test_packed_file, 'r') as fi: images = fi.get('X') X = images with h5py.File(constants.test_features_file, 'w') as fo: XC1 = encoder(X, centroids, W, M, chunk_size=constants.chunk_size, batch_size=constants.batch_size, Y=None, fo=fo) # XC2 = encoder_slow(X, centroids, W, M, batch_size=3) # np.testing.assert_allclose(XC1, XC2, rtol=1e-2)