Python model.MLP Examples

The following are 5 code examples of model.MLP(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module model , or try the search function .
Example #1
Source File: make_model.py    From neural-fingerprinting with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def make_basic_cnn(nb_filters=64, nb_classes=10,
                   input_shape=(None, 28, 28, 1)):
    layers = [Conv2D(nb_filters, (8, 8), (2, 2), "SAME"),
              ReLU(),
              Conv2D(nb_filters * 2, (6, 6), (2, 2), "VALID"),
              ReLU(),
              Conv2D(nb_filters * 2, (5, 5), (1, 1), "VALID"),
              ReLU(),
              Flatten(),
              Linear(nb_classes),
              Softmax()]

    model = MLP(nb_classes, layers, input_shape)
    return model 
Example #2
Source File: load.py    From chainer with MIT License 5 votes vote down vote up
def load_npz_file_to_model(npz_filename='model.npz'):
    # Create model object first
    model1 = model.MLP()

    # Load the saved parameters into the model object
    chainer.serializers.load_npz(npz_filename, model1)
    print('{} loaded!'.format(npz_filename))

    return model1 
Example #3
Source File: load.py    From chainer with MIT License 5 votes vote down vote up
def load_hdf5_file_to_model(hdf5_filename='model.h5'):
    # Create another model object first
    model2 = model.MLP()

    # Load the saved parameters into the model object
    chainer.serializers.load_hdf5(hdf5_filename, model2)
    print('{} loaded!'.format(hdf5_filename))

    return model2 
Example #4
Source File: make_model.py    From cleverhans with MIT License 5 votes vote down vote up
def make_basic_cnn(nb_filters=64, nb_classes=10,
                   input_shape=(None, 28, 28, 1)):
  layers = [Conv2D(nb_filters, (8, 8), (2, 2), "SAME"),
            ReLU(),
            Conv2D(nb_filters * 2, (6, 6), (2, 2), "VALID"),
            ReLU(),
            Conv2D(nb_filters * 2, (5, 5), (1, 1), "VALID"),
            ReLU(),
            Flatten(),
            Linear(nb_classes),
            Softmax()]

  model = MLP(nb_classes, layers, input_shape)
  return model 
Example #5
Source File: example.py    From FlexTensor with MIT License 4 votes vote down vote up
def gemm_config(M, N, K, logits_dict):
    spatial_split_parts = 4
    reduce_split_parts = 4
    unroll_max_factor = 10

    sy = any_factor_split(M, spatial_split_parts)
    sx = any_factor_split(N, spatial_split_parts)
    sk = any_factor_split(K, reduce_split_parts)
    unroll = []
    for i in range(1):
        for j in range(unroll_max_factor + 1):
            unroll.append([i, 2**j])

    def _rational(lst, max_val):
        return torch.FloatTensor([[y / float(max_val) for y in x] for x in lst])
    nsy = _rational(sy, M)
    nsx = _rational(sx, N)
    nsk = _rational(sk, K)
    
    n_unroll = torch.FloatTensor([[x[0] / float(2) + 0.5, math.log2(x[1]) / 1] for x in unroll])

    # get logits
    spatial_logits = logits_dict["spatial"]
    reduce_logits = logits_dict["reduce"]
    unroll_logits = logits_dict["unroll"]
    
    # make choice
    feature_size = len(logits_dict["spatial"][0])
    split_classifier = model.MLP(feature_size + spatial_split_parts)
    unroll_classifier = model.MLP(feature_size + 2)
    cy = torch.argmax(split_classifier(torch.cat([nsy, torch.zeros([nsy.shape[0], feature_size]) + spatial_logits[0]], dim=1)))
    cx = torch.argmax(split_classifier(torch.cat([nsx, torch.zeros([nsx.shape[0], feature_size]) + spatial_logits[1]], dim=1)))
    ck = torch.argmax(split_classifier(torch.cat([nsk, torch.zeros([nsk.shape[0], feature_size]) + reduce_logits[0]], dim=1)))
    cu = torch.argmax(unroll_classifier(torch.cat([n_unroll, torch.zeros([n_unroll.shape[0], feature_size]) + unroll_logits], dim=1)))

    print(cy, cx, ck, cu)
    
    # print choice
    print("Print choice")
    print("split y =", sy[cy])
    print("split x =", sx[cx])
    print("split k =", sk[ck])
    print("unroll", unroll[cu])

    # make config
    op_config = [{
        "spatial": [sy[cy], sx[cx]],
        "reduce": [sk[ck]],
        "inline": [],
        "unroll": [unroll[cu]]
    }]
    graph_config = {
        "spatial": [], 
        "reduce": [], 
        "inline": [[0]], 
        "unroll": []
    }
    return Config(op_config, graph_config)