예제 #1
0
파일: fc.py 프로젝트: bionicles/neuromax
 def build(self, shape):
     dense = L.Dense(units=self.units)
     dense.build(shape)
     k_shape = dense.kernel.shape
     b_shape = dense.bias.shape
     k_size = get_size(k_shape)
     b_size = get_size(b_shape)
     self.hyper_layer = N.Layer(self.ai, units=k_size + b_size)
     self.reshape_kernel = L.Reshape(k_shape)
     self.reshape_bias = L.Reshape(b_shape)
     self.split = L.Lambda(lambda x: tf.split(x, [k_size, b_size]))
     super().build(shape)
def auto_index(elastic, in_file_path, out_path):
    with open(in_file_path, "r") as ini:
        best_index = ""
        best_index_bytes = "a".encode()
        biggest_size = 0
        for line in ini:
            if not line.startswith("{\"index") and not line.startswith("\n"):
                json_line = json.loads(line)
                # print(json_line)
                auto_index_elastic.bulk_data(elastic, json_line)
                auto_index = auto_index_elastic.get_mapping(elastic)
                auto_index_bytes = json.dumps(auto_index).encode()
                auto_index_elastic.clear_test_mapping(elastic)

                if auto_index_bytes != best_index_bytes:
                    size_obj = tools.get_size(auto_index)
                    if size_obj.exact_size > biggest_size:
                        best_index = auto_index
                        biggest_size = size_obj.exact_size
                        best_index_bytes = auto_index_bytes
                        print(best_index)
                        print(size_obj.size, size_obj.unit)
                        with open(out_path, "w") as out:
                            json.dump(best_index["tmp_index"], out)
    return best_index["tmp_index"]
예제 #3
0
 def build(self, shape):
     dense = L.Dense(self.units)
     dense.build([shape[0], get_size(shape[1:])])
     self.kernel = self.add_weight(
         "kernel", dense.kernel.shape, initializer=self.init,
         trainable=self.trainable)
     self.flatten = L.Flatten()
     super().build(shape)
예제 #4
0
 def __init__(self, AI, out_shape, key=KEY):
     super(Resizer, self).__init__()
     size = get_size(out_shape)
     self.resize = nature.FC(units=size)
     self.reshape = L.Reshape(out_shape)
     self.fn = nature.Fn(AI, key=key)
     self.out_shape = out_shape
     self.flatten = L.Flatten()
     self.built = True
예제 #5
0
def createPathUi():
    top = Toplevel()
    top.title('图片目录选择')
    top.geometry(tools.get_size(width=240, height=100))
    top.resizable(0, 0)
    pathVar = StringVar()

    lable_path = Label(top, text='路径选择:')
    entry_path = Entry(top, textvariable=pathVar)
    button = Button(top,
                    text="选择目录",
                    width=19,
                    command=lambda: selectPath(pathVar, top))
    # 放置部件
    lable_path.grid(row=0, column=0)
    entry_path.grid(row=0, column=1)
    button.grid(row=1, column=1)
예제 #6
0
    def init_Window(self):
        # GUI标题
        self.master.title("OCR批量识别身份证")
        # 窗口大小
        self.master.geometry(tools.get_size(width=300, height=400))
        self.master.resizable(0, 0)

        MenuBar = Menu(self.master)
        MenuBar.add_cascade(label="开始运行", command=lambda: ocr.main(text))
        MenuBar.add_cascade(label="百度API设置", command=MenuBarUi.createAPiUi)
        MenuBar.add_cascade(label="选择图片目录", command=MenuBarUi.createPathUi)
        self.master.config(menu=MenuBar)
        scroll = Scrollbar()
        text = Text(self.master, width=40, height=400)
        scroll.pack(side=RIGHT, fill=Y)
        text.pack(side=RIGHT, fill=Y)
        scroll.config(command=text.yview)
        text.config(yscrollcommand=scroll.set)
예제 #7
0
def createAPiUi():
    top = Toplevel()
    top.title('API设置')
    top.geometry(tools.get_size(width=240, height=100))
    top.resizable(0, 0)
    akVar = StringVar()
    skVar = StringVar()
    lable_ak = Label(top, text='Api Key:')
    lable_sk = Label(top, text='Secret Key:')
    entry_ak = Entry(top, textvariable=akVar)
    entry_sk = Entry(top, textvariable=skVar)
    button = Button(top,
                    text="确定",
                    width=19,
                    command=lambda: submit(akVar=akVar, skVar=skVar, top=top))
    # 放置部件
    lable_ak.grid(row=0, column=0)
    lable_sk.grid(row=1, column=0)
    entry_ak.grid(row=0, column=1)
    entry_sk.grid(row=1, column=1)
    button.grid(row=2, column=1)
예제 #8
0
 def __init__(self, agent, task_id, in_spec, out_spec, in_number=None):
     super(Interface, self).__init__()
     self.pull_numbers = agent.pull_numbers
     self.pull_choices = agent.pull_choices
     self.agent = agent
     self.probabilistic = agent.probabilistic
     self.task_id, self.in_spec, self.out_spec = task_id, in_spec, out_spec
     self.brick_id = f"{task_id}{'_'+str(in_number) if in_number else ''}_{in_spec.format}_to_{out_spec.format}_{generate()}"
     self.debug = 1 if "predictor" in self.brick_id else 0
     log("", debug=self.debug)
     log(f"Interface.__init__ -- {self.brick_id}", debug=self.debug)
     log("in_spec", in_spec, debug=self.debug)
     log("out_spec", out_spec, debug=self.debug)
     self.input_layer_number = in_number
     self.shape_variable_key = None
     if self.in_spec.format == "image":
         self.channels_before_concat_coords = self.in_spec.shape[-1]
         self.size_to_resize_to = get_hw(self.in_spec.shape)
         encoder_shape = self.add_coords_to_shape(self.in_spec.shape)
         self.in_spec = get_spec(format="image", shape=encoder_shape)
         self.in_spec.size = get_size(encoder_shape)
     super(Interface, self).__init__()
     self.build()
예제 #9
0
import sys
from trie import Trie
from bloom_filter import BloomFilter
from tools import get_size

if __name__ == '__main__':
    bf_dups = 0
    tr = Trie()
    bf = BloomFilter(capacity=700000, error_rate=0.001)
    with open("words.txt") as file:
        for line in file:
            tr.put(line.strip())
            if bf.put(line.strip()):
                print("Duplicate in bloom filter: {0}".format(line.strip()))
                bf_dups += 1

    print("Trie. number of objects put: {0}".format(len(tr)))
    print("Bloom filter. number of objects put: {0}".format(len(bf)))
    print()
    print("Trie. Size of the object: {0}".format(sys.getsizeof(tr)))
    print("Bloom filter. Size of the object: {0}".format(sys.getsizeof(bf)))
    print()
    print("Trie. Size of the object(full): {0}".format(get_size(tr)))
    print("Bloom filter. Size of the object(full): {0}".format(get_size(bf)))
    print()
    print("Bloom filter errors: {0}".format(bf_dups))
    print("----------------------------------------------------------")
예제 #10
0
파일: OP_1D.py 프로젝트: bionicles/neuromax
def get_units(shape):
    d_in = get_size(shape)
    return d_in * d_in + 1