Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add create model function for the dynamic model #1092

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions examples/model_selection_psql/ms_model_mlp/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,49 @@ def train_one_batch(self, x, y, dist_option, spars, synflow_flag):

def set_optimizer(self, optimizer):
self.optimizer = optimizer


def create_model(pretrained=False, **kwargs):
"""Constructs a CNN model.

Args:
pretrained (bool): If True, returns a pre-trained model.

Returns:
The created CNN model.
"""
model = MSMLP(**kwargs)

return model


__all__ = ['MLP', 'create_model']

if __name__ == "__main__":
np.random.seed(0)

parser = argparse.ArgumentParser()
parser.add_argument('-p',
choices=['float32', 'float16'],
default='float32',
dest='precision')
parser.add_argument('-g',
'--disable-graph',
default='True',
action='store_false',
help='disable graph',
dest='graph')
parser.add_argument('-m',
'--max-epoch',
default=1001,
type=int,
help='maximum epochs',
dest='max_epoch')
args = parser.parse_args()

model = MLP(data_size=2, perceptron_size=3, num_classes=2)

# attach model to graph
model.set_optimizer(sgd)
model.compile([tx], is_train=True, use_graph=args.graph, sequential=True)
model.train()
Loading