예제 #1
0
def main():
    config = fetch_config(args.input)
    validator = ConfigValidator(args.input)

    validator.check(config, "memory")
    validator.check(config["memory"], "sections")

    sections = get_sections(config["memory"], validator)

    memory = config["memory"]
    validator.check(memory, "heap")
    validator.check(memory["heap"], "size")
    validator.check(memory, "stack")
    validator.check(memory["stack"], "size")
    heap = hex(parse_size(config["memory"]["heap"]["size"]))
    stack = hex(parse_size(config["memory"]["stack"]["size"]))

    base = "arm/common.ld"

    if "linker_script" in config:
        base = config["linker_script"]

    rendered = get_template().render(sections=sections,
                                     heap=heap,
                                     stack=stack,
                                     common_script=base)

    make_dir(args.output)

    with open(args.output + "/linker_script.ld", "w") as output:
        output.write(rendered)
    with open(args.output + "/memory_config.cmake", "w") as output:
        for section in sections:
            output.write("set(" + section["name"] + "_" + "size" + " " +
                         section["length"] + " CACHE INTERNAL \"\" FORCE)\n")
예제 #2
0
 def export(self, export_path):
     """
     Export optimizable parameters to the specified export path
     """
     make_dir(export_path)
     for key, param in self.__params.items():
         np.save(join(export_path, "{}.npy".format(key)), param.get_value())
예제 #3
0
 def set_debug_info(self, pca_weights, patch_sz, debug_path, prefix):
     make_dir(debug_path)
     self.__debug_enabled = True
     self.__pca_weights = pca_weights
     self.__patch_sz = patch_sz
     self.__debug_path = debug_path
     self.__prefix = '' if prefix == None else prefix + '_'
예제 #4
0
 def export(self, path):
     """
     Export selected parameters matrices to npy files
     """
     make_dir(path)
     for param in self._params:
         fn = os.path.join(path, "{}.npy".format(str(param)))
         np.save(fn, param.get_value(borrow=True))
예제 #5
0
    def export(self, path):
        """
        Export parameters shared variables to npy files.  Files are named
        according of the "name" argument of the shared variable

        Parameters
        ----------
        path:       string
                    path for which to export parameter files
        """
        make_dir(path)
        for param in self._params:
            fn = join(path, "{}.npy".format(str(param)))
            np.save(fn, param.get_value(borrow=True))
예제 #6
0
    def export(self, path, which=None):
        """
        Export selected parameters matrices to npy files

        Parameters
        ----------
        which:      string or NoneType
                    if which == encoder, then export only encoder parameters.
                    otherwise, it returns all parameters
        """
        make_dir(path)
        for param in self._params:
            fn = os.path.join(path, "{}.npy".format(str(param)))
            np.save(fn, param.get_value(borrow=True))
예제 #7
0
            def __init__(self,
                         obj,
                         debug_path=None,
                         patch_sz=None,
                         pca=None,
                         prefix=''):
                self.W = obj.W
                self.layer_id = obj.layer_id
                self.debug_path = join(debug_path, 'filters')
                self.patch_sz = patch_sz
                self.pca = pca
                self.prefix = prefix

                # Make output directory
                make_dir(self.debug_path)
예제 #8
0
파일: tiff.py 프로젝트: fulQuan/ift6266h15
def write_paged_tiff(fn, img_list):
    """
    Reads a paged tiff file using the ImageMagick library.
    This is really ugly but didn't find any other way...

    Parameters
    ----------
    fn :        string
                path to tif file

    img_list    list of numpy arrays
                list of images where element i of the list corresponds to page i of the tiff file
    """

    path = os.path.split(fn)[0]
    for i in range(1000):
        time = datetime.now().strftime("%Y%m%d_%Hh%Mm%Ss_%f")
        stamp = str(np.random.randint(10000000, 99999999))
        tmp = os.path.join(path, time + stamp)
        if not (os.path.isdir(tmp)):
            make_dir(tmp)
            try:
                tmp_fn_list = []
                for k, img in enumerate(img_list):
                    if img.ndim == 2:
                        write_img = (img * 255.0).astype(np.uint8)
                    elif img.ndim == 3:
                        write_img = (img[:, :, ::-1] * 255.0).astype(np.uint8)
                    tmp_fn = os.path.join(tmp, '{}.tif'.format(k))
                    tmp_fn_list += [tmp_fn]
                    cv2.imwrite(tmp_fn, write_img)

                call = 'convert'
                for img_fn in tmp_fn_list:
                    call += ' '
                    call += img_fn
                call += ' '
                call += fn
                p = popen(call, env=os.environ, shell=True)
                p.wait()
            except:
                delete(tmp)
                raise
            delete(tmp)
            return

    raise IOError, 'Could not save {} because a hidden temporary directory could not be created'.format(
        fn)
예제 #9
0
    def debug_call(self, debug_path=None, patch_sz=None, pca=None, prefix=''):

        if not debug_path:
            return

        # Make output directory
        make_dir(debug_path)

        # Convert weight matrix into filter imagelets and output to file
        if patch_sz:
            W = T.dot(pca,
                      self.W).eval() if pca != None else self.W.get_value()
            nb_frames = W.shape[0] / np.prod(patch_sz)
            W = W.transpose(1, 0)
            W = W.reshape((W.shape[0], nb_frames, -1))
            W = W.transpose(1, 2, 0)
            for i, w in enumerate(W):
                filterstoimg(w,
                             patch_sz,
                             fn=join(
                                 debug_path, '{}_{}_frame_{}.png'.format(
                                     prefix, str(self.W), i)))
예제 #10
0
def main():
    make_dir(args.output_directory)
    with open(args.board) as board_file:
        board = json.loads(board_file.read())
    processed_files.append(args.board)
    configs = get_all_configs(board["info"]["mcu"], args.input_directory, args.user_directory)
    config = merge_configs(configs)
    config = merge(board, config)
    config = patch_with_other_config(config, args.user_configs)
    if "parent" in config:
        del config["parent"]

    with open(args.output_directory + "/soc_config.json", "w") as file:
        json.dump(config, file)

    cmake_soc_file = args.output_directory + "/soc_config.cmake"
    with open(cmake_soc_file, "w") as soc_config:
        write_node(config, "", soc_config)
        soc_config.write("set (board_configuration_path {board_configuration_path} CACHE INTERNAL \"\" FORCE)\n".format(
            board_configuration_path = Path(processed_files[0]).parent
        ))
        for file in processed_files:
            soc_config.write("set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS " + str(file) + ")\n")
예제 #11
0
 def _set_debug_info(self, pca_weights, debug_path):
     make_dir(debug_path)
     self.debug = True
     self.pca_weights = pca_weights
     self.debug_path = debug_path
예제 #12
0
 def set_debug_info(self, debug_path, pca_weights=None, prefix=None):
     make_dir(debug_path)
     self.__debug = True
     self.__debug_path = debug_path
     self.__prefix = '' if prefix == None else prefix + '_'