Beispiel #1
0
def makeTorrent(fname, folder = "."):
    data = {
        "announce": "http://open.nyaatorrents.info:6544/announce",
        "announce-list": [["http://open.nyaatorrents.info:6544/announce"],["udp://tracker.openbittorrent.com:80/announce"]],
        "info": {},
        "creation date": long(time.time()),
        "comment": "#[email protected]",
        "created by": "Servrhe",
        "encoding": "UTF-8"
    }
    data["info"]["name"] = normalize(fname)
    data["info"]["length"] = size = os.path.getsize("{}/{}".format(folder, fname))
    # 1MB pieces if file > 512MB, else 512KB pieces
    data["info"]["piece length"] = piece_length = 2**20 if size > 512*1024*1024 else 2**19
    pieces = []
    with open("{}/{}".format(folder, fname), "rb") as f:
        p = 0L
        while p < size:
            chunk = f.read(min(piece_length, size - p))
            pieces.append(hashlib.sha1(chunk).digest())
            p += piece_length
    data["info"]["pieces"] = "".join(pieces)
    torrentname = fname + ".torrent"
    with open("{}/{}".format(folder, torrentname), "wb") as f:
        f.write(bencode(data))
    return torrentname
Beispiel #2
0
 def update_topic(self):
     shows = yield self.load("shows","current_episodes")
     shows = [(s["abbr"], s["current_ep"], s["last_release"]) for s in shows["results"]]
     shows.sort(key=lambda x: x[2], reverse=True)
     shows = ", ".join(["{} {:d}".format(s[0],s[1]) for s in shows[:self.config.topic[1]]])
     topic = " || ".join([self.config.topic[0], shows, "Mahoyo progress: {:0.2f}%".format(self.config.topic[2])] + self.config.topic[3:])
     self.protocols[0].topic("#commie-subs", normalize(topic))
Beispiel #3
0
def train():
    loader = SVHNLoader('./data')
    net = shufflenet((32, 32, 3))
    net.train(loader.train_samples, loader.train_labels, iteration_steps=2000, chunkSize=64)
    net.test(loader.test_samples, loader.test_labels, chunkSize=200)
    image = cv2.imread('./2.jpg')
    image = cv2.resize(image, (32, 32), interpolation=cv2.INTER_CUBIC)
    # image = utils.gray(image)
    image = utils.normalize(image)
    n = net.predict(image)
    print(np.argmax(n))
Beispiel #4
0
def clean(o):
    if isinstance(o, dict):
        c = {}
        for k, v in o.items():
            c[clean(k)] = clean(v)
        return c
    elif isinstance(o, list):
        return [clean(v) for v in o]
    elif isinstance(o, basestring):
        return normalize(o)
    else:
        return o
Beispiel #5
0
def smooth_depth_map(depth, conf, percentile, fore_mask):
    print('Smoothing depth map with %d-th percentile...' % (percentile))

    # Mark pixels with confidence < x percentile as not credible in mask, so that
    # we can inpaint these areas from high-confidence pixels.
    conf_thresh = np.percentile(conf, percentile)
    mask = np.zeros(depth.shape, np.uint8)
    mask[(conf < conf_thresh) & (fore_mask == 1)] = 1

    output_depth = np.array(depth)
    output_depth[mask == 1] = VERY_FAR
    viz.normalize_and_draw(output_depth, './doll_data_out/masked_depth.jpg', 0)

    norm_depth, scale, shift = utils.normalize(depth, 0, 255.0)
    smooth_depth = np.array(norm_depth, np.uint8)
    smooth_depth = cv2.inpaint(smooth_depth, mask, \
        DEPTH_SMOOTH_INPAINT_SIZE, cv2.INPAINT_TELEA)
    viz.normalize_and_draw(smooth_depth, './doll_data_out/noisy_depth.jpg', 0)
    smooth_depth = cv2.fastNlMeansDenoising(smooth_depth, \
        h=DEPTH_SMOOTH_DENOISE_STRENGTH)
    smooth_depth = np.array(smooth_depth, np.float32)
    smooth_depth *= scale
    smooth_depth += shift
    return smooth_depth
Beispiel #6
0
def smooth_depth_map_new(depth, conf, mask, img):
    img = np.array(cv2.cvtColor(img, cv2.COLOR_BGR2GRAY), np.float32)
    adj_conf = np.array(conf)
    adj_conf[mask == 1] = utils.hist_equalize(conf[mask == 1], (1e-3, 1.0))
    adj_conf[mask == 1] = np.exp(-1.0 / adj_conf[mask == 1])
    adj_conf[mask == 0] = 0.0
    win_hsize = SMOOTH_WINDOW_HALFSIZE
    win_size = win_hsize * 2 + 1
    dist_filter = np.zeros([win_size, win_size], np.float32)
    for y in range(win_size):
        for x in range(win_size):
            dist_filter[y, x] = (y - win_hsize)**2 + (x - win_hsize)**2
    dist_filter = np.exp(-dist_filter / DIST_COEFF**2)
    depth = np.array(depth, np.float32)
    status_mask = np.array(mask, np.uint8)
    weight_map = np.zeros(depth.shape, np.float32)

    thresh = 1.0
    decay = SMOOTH_DECAY

    np.set_printoptions(precision=3)
    while True:
        thresh *= decay
        print('Smoothing with thresh=%.3f' % thresh)
        new_finalized = (adj_conf > math.exp(-1.0 / thresh)) & (status_mask
                                                                == 1)
        num_new_fin = np.count_nonzero(new_finalized)
        print('\tNewly finalized pixels: %d' % num_new_fin)
        if num_new_fin == 0:
            break
        status_mask[new_finalized] = 2
        for y in range(depth.shape[0]):
            for x in range(depth.shape[1]):
                if not new_finalized[y, x]:
                    continue
                intensity_weight = get_intensity_weight(img, y, x, win_hsize)
                weight_patch = intensity_weight * dist_filter
                weight_map[y - win_hsize : y + win_hsize + 1, \
                           x - win_hsize : x + win_hsize + 1] += weight_patch
        new_expandable = (weight_map > EXPAND_THRESH) & (status_mask == 1)
        print('\tNewly expandable pixels: %d' %
              np.count_nonzero(new_expandable))

        for y in range(depth.shape[0]):
            for x in range(depth.shape[1]):
                if not new_expandable[y, x]:
                    continue
                ready_patch = status_mask[\
                    y - win_hsize : y + win_hsize + 1, \
                    x - win_hsize : x + win_hsize + 1] == 2
                get_intensity_weight(img, y, x, win_hsize)
                conf_patch = adj_conf[\
                    y - win_hsize : y + win_hsize + 1, \
                    x - win_hsize : x + win_hsize + 1]
                depth_patch = depth[\
                    y - win_hsize : y + win_hsize + 1, \
                    x - win_hsize : x + win_hsize + 1]
                weight_patch = ready_patch * dist_filter * intensity_weight
                d = np.sum(weight_patch * conf_patch * depth_patch) / \
                    np.sum(weight_patch * conf_patch)
                c = np.sum(weight_patch * conf_patch) / \
                    np.sum(weight_patch)
                depth[y, x] = d
                adj_conf[y, x] = c * CONF_DECAY

    viz.normalize_and_draw(depth, './doll_data_out/unsmoothened_depth.jpg', 0)
    norm_depth, scale, shift = utils.normalize(depth, 0, 255.0)
    smooth_depth = np.array(norm_depth, np.uint8)
    smooth_depth = cv2.fastNlMeansDenoising(smooth_depth, \
        h=DEPTH_SMOOTH_DENOISE_STRENGTH)
    smooth_depth = np.array(smooth_depth, np.float32)
    smooth_depth = (smooth_depth * scale) + shift
    return smooth_depth
Beispiel #7
0
        B_mat.transpose()) + np.random.randn(n_date, n_name) * sd_idio
    print(B_mat)
    f2_mat = f_mat**2
    print(cpt.cpt_detect_minseglen_PELT(1, 1, f2_mat, n_factor, 5))

    return y_mat


def normalize(y_mat):
    return (y_mat - y_mat.mean(axis=0)) / y_mat.std(axis=0)


if __name__ == "__main__":
    y_mat = data_toy_simulation()
    #y_mat = np.loadtxt(open("/tmp/y_mat.csv", "rb"), delimiter=",")
    y_mat = utils.normalize(y_mat)

    model = FactorModel(y_mat, k_max=20)

    model.cpt_config()
    model.param_init()

    delta0_steps = [1, 5, 10, 20]

    for delta0 in delta0_steps:
        model.delta0_reconfig(delta0)
        model.em_iterator(200, True)
        print(model.k_plus)
        print(model.Beta[:, :model.k_plus])
        model.em_iterator(200, False)
        print(model.k_plus)
Beispiel #8
0
 def msg(self, channel, message):
     irc.IRCClient.msg(self, channel, normalize(message))
Beispiel #9
0
 def notice(self, user, message):
     irc.IRCClient.notice(self, user, normalize(message))
Beispiel #10
0
def test_normalize(source, expected):
    assert normalize(source) == expected
Beispiel #11
0
                self.backpropagation(x, y)
                if (ind+1) % self.mbs == 0:
                    self.update_gradients()
            self.update_gradients()
            print('ce loss', ce)
            print('train_acc', yt*100/X.shape[0])  # ,'val_acc', self.accuracy\
            # (val_set[0],val_set[1]))


img = np.array(cv2.imread('img.jpg', cv2.IMREAD_GRAYSCALE))
# print(img.shape)
# img = Conv2D(filters=2).filter(norm(img))
# print(img.shape)
# #display(img[:,:,1])
# img = Maxpool().filter(norm(img))
# print(img.shape)
# #display(img[:,:,1])
# y = Dense(units=10, input_shape=(113*113*2)).forward(img.flatten().reshape(25538, 1))
# print(y.shape)

X_train, y_train, X_val, y_val = load_mnist(reshape=True, n_rows=1000)
model = Model().sequential([Conv2D(filters=2),
                            Maxpool(),
                            Flatten(),
                            Dense(10)])
model.compile(X_train[0])
X_train = normalize(X_train)

# display(X_train[0])
model.fit(X_train, y_train, mbs=1, epoch=10)
Beispiel #12
0
def test_re_kids(src):
    assert kids_finder(normalize(src))
Beispiel #13
0
    def render(self, objects):
        camera = self.camera
        ratio = float(self.width) / self.height
        screen = (-1, 1 / ratio, 1, -1 / ratio)  # left, top, right, bottom

        for i, y in enumerate(np.linspace(screen[1], screen[3], self.height)):
            for j, x in enumerate(np.linspace(screen[0], screen[2],
                                              self.width)):
                # screen is on origin
                pixel = np.array([x, y, 0])
                # origin =  np.array([x, y, 1])
                origin = camera
                direction = utils.normalize(pixel - origin)

                color = np.zeros((3))
                reflection = 1

                for k in range(self.max_depth):
                    # check for intersections
                    nearest_object, min_distance = utils.nearest_intersected_object(
                        objects, origin, direction)
                    if nearest_object is None:
                        break

                    intersection = origin + min_distance * direction
                    # normal_to_surface = utils.normalize(intersection - nearest_object.center)
                    normal_to_surface = nearest_object.normal_to_surface(
                        intersection)
                    shifted_point = intersection + 1e-5 * normal_to_surface

                    for light in self.lights:

                        intersection_to_light = utils.normalize(
                            light['position'] - shifted_point)

                        _, min_distance = utils.nearest_intersected_object(
                            objects, shifted_point, intersection_to_light)
                        intersection_to_light_distance = np.linalg.norm(
                            light['position'] - intersection)
                        is_shadowed = min_distance < intersection_to_light_distance

                        if is_shadowed:
                            break

                        illumination = np.zeros((3))

                        # ambiant
                        illumination += nearest_object.material.ambient * light[
                            'ambient']

                        # diffuse
                        illumination += nearest_object.material.diffuse * light[
                            'diffuse'] * np.dot(intersection_to_light,
                                                normal_to_surface)

                        # specular
                        intersection_to_camera = utils.normalize(camera -
                                                                 intersection)
                        H = utils.normalize(intersection_to_light +
                                            intersection_to_camera)
                        illumination += nearest_object.material.specular * light[
                            'specular'] * np.dot(normal_to_surface, H)**(
                                nearest_object.material.shininess / 4)

                        # reflection
                        color += reflection * illumination
                        reflection *= nearest_object.material.reflection

                    origin = shifted_point
                    direction = utils.reflected(direction, normal_to_surface)

                # image[i, j] = np.clip(color, 0, 1)
                self.display.set_at((j, i), utils.toRgb(color))
            print("%d/%d" % (i + 1, self.height))
            pygame.display.flip()