Ejemplo n.º 1
0
def save(name='default'):
    """
    保存id和data数据
    :return:
    """
    from context.resource_manager import Properties
    from pandas import DataFrame, Series
    path = os.path.join(Properties.getXmlLocation() + name + ".xml")
    from xml.dom.minidom import parse, parseString
    images = parse(path)
    id = []
    data = []
    for node in images.getElementsByTagName("Image"):
        idNode = node.getElementsByTagName("id")[0].childNodes[0].data
        id.append(idNode)
        dataNode = node.getElementsByTagName("data")[0].childNodes[0].data
        dataNode = dataNode[1:-1].split(',')
        data.append(dataNode)
    id = np.asarray(id)
    id = Series(id)
    data = np.asarray(list(map(conv, data)), dtype=np.float)
    if not os.path.exists(Properties.getDefaultDataFold() + "/cache/" + name):
        #f=open(Properties.getDefaultDataFold()+"/csv/threshold.csv","w")
        #f.close()
        os.makedirs(Properties.getDefaultDataFold() + "/cache/" + name)
    np.save(Properties.getRootPath() + "/data/cache/" + name + "/id.npy", id)
    np.save(Properties.getRootPath() + "/data/cache/" + name + "/data.npy",
            data)
Ejemplo n.º 2
0
    def getXmlData(self, save=False, relative=True):
        """
        保存id和data数据
        :return:
        """

        if relative:
            path = os.path.join(Properties.getRootPath()+Properties.getXmlLocation() + self.name + ".xml")
        else:
            path = self.name
        images = parse(path)
        id = []
        data = []
        for node in images.getElementsByTagName(self.tag):
            idNode = node.getElementsByTagName("id")[0].childNodes[0].data
            id.append(idNode)
            dataNode = node.getElementsByTagName("data")[0].childNodes[0].data
            dataNode = dataNode[1:-1].split(',')
            data.append(dataNode)
        id = np.asarray(id)
        id = Series(id)
        data = np.asarray(list(map(conv, data)), dtype=np.float)
        if save:
            if not os.path.exists(Properties.getRootPath()+Properties.getDefaultDataFold() + "/cache/" + self.name):
                # f=open(Properties.getDefaultDataFold()+"/csv/threshold.csv","w")
                # f.close()
                os.makedirs(Properties.getRootPath()+Properties.getDefaultDataFold() + "/cache/" + self.name)
            np.save(Properties.getRootPath()+Properties.getRootPath() + "/data/cache/" + self.name + "/id.npy", id)
            np.save(Properties.getRootPath()+Properties.getRootPath() + "/data/cache/" + self.name + "/data.npy", data)

        return id, data