def from_string(cls, s, ctx=mx.cpu(0)): tab = s.split("/LAYER\n") info_net = tab.pop(0) tab_net = info_net.split("\n") assert tab_net[0] == "//" + cls.__name__ + " V" + str( cls.VERSION ), "This file doesn't fit the format (wrong class or wrong version)" tab_net2 = [] for chain in tab_net: if "/" not in chain and chain != "": tab_net2.append(chain.strip(" ")) sizes = [] for chain in tab_net2.pop(0).split(" "): sizes.append(int(chain)) net = cls(sizes, ctx=ctx) assert net.layersNumber == len( tab ), "Number of layers doesn't fit the number of sizes in the file." for i in range(net.layersNumber): net.set_layer(Layer.from_string(tab[i], ctx), i) return net