Пример #1
0
def all_iotnets():
    for spacename in networks.ARCH_SPACES:
        print(spacename)
        # Check if you can construct the network.
        law_config = networks.get_law_config(spacename, "s1")
        net_args = networks.sample_from_law(spacename, law_config, 0)
        net = networks.build(spacename, 12, net_args)
    print("OK")
Пример #2
0
def demo():
    for arch in ['ResNet18', 'ResNet101', 'ResNet152']:
        print("REFERENCE model: {}".format(arch))
        net = networks.build(arch, 10, net_args=None)
        ts = latency_run(net)


    spacename = "random_net_mobilenetv2"
    for law in ["s1", "s3", "s6"]:
        print("OUR Constraint ARCH searchspace, based on {} with sampling law {}".format(spacename, law))
        law_config = networks.get_law_config(spacename, law)
        net_args = networks.sample_from_law(spacename, law_config, 0)
        net = networks.build(spacename, 10, net_args)
        ts = latency_run(net)
Пример #3
0
def run_all():
    # Open configuration file
    configs = load_json("configs/NetConfigs.json")

    results = []
    # Run all configurations
    for c in configs:
        law_config = networks.get_law_config(c["spacename"], c["law"])
        net_args = networks.sample_from_law(c["spacename"], law_config,
                                            c["id"])
        net = networks.build(c["spacename"], 10, net_args)
        ts = latency_run(net, device="cpu", bs=1, rep=10, verbose=True)
        # Clean the data
        c["t_avg"] = np.mean(1000 * ts[5:])
        c["t_std"] = np.std(1000 * ts[5:])
        results.append(c)

    # Save results (with configurations)
    write_json("results.json", results)
Пример #4
0
def run_model(config, root_models, device="cpu"):
    # Defines the model topology
    law_config = networks.get_law_config(config["spacename"], config["law"])
    net_args = networks.sample_from_law(config["spacename"], law_config,
                                        config["id"])
    net = networks.build(config["spacename"], 10, net_args)

    net = net.to(device)

    # Defines where the model is stored
    ckpt_model = os.path.join(root_models,
                              "{}_ckpt.t7".format(config["runid"]))

    # Loading model
    mode = "None" if device == "cuda" else "rm"
    net, acc = load_net(net, ckpt_model, device, mode=mode, verbose=False)
    print("Loaded net acc: {}".format(acc))

    # Latency measurement
    ts = latency_run(net, device="cpu", bs=1, rep=10, verbose=True)
    return np.mean(1000 * ts[5:])