Caffe2 - Python API
A deep learning, cross platform ML framework
sparseNN.py
1 #########################################################
2 #
3 # DO NOT EDIT THIS FILE. IT IS GENERATED AUTOMATICALLY. #
4 # PLEASE LOOK INTO THE README FOR MORE INFORMATION. #
5 #
6 #########################################################
7 
8 
9 # coding: utf-8
10 
11 # In[ ]:
12 
13 
14 from caffe2.python import (
15  core,
16 )
17 
18 from caffe2.python.fb.dper.layer_models.models import sparse_nn
19 from fblearner.flow.projects.dper.preprocs.ads import build_preproc
20 from fblearner.flow.projects.dper.preprocs.ads_feature_processor import (
21  ads_feature_processor,
22 )
23 from hiveio import par_init # noqa
24 import fblearner.flow.projects.dper.flow_types as T
25 import fblearner.flow.projects.dper.utils.assemble as assemble_utils
26 import fblearner.flow.projects.dper.utils.data as data_utils
27 import fblearner.flow.projects.dper.utils.visualize as vis_utils
28 import fblearner.flow.projects.dper.workflows.ads_config as default_config
29 
30 import fblearner.flow.projects.dper.ifbpy.compute_meta as compute_meta
31 from fblearner.flow.projects.dper.ifbpy.execution import test_model_locally
32 import fblearner.flow.projects.dper.utils.visualize as vis_utils
33 import fblearner.flow.projects.dper.utils.perf_estimator_execution as perf_estimator_execution
34 
35 import json
36 core.GlobalInit(['ifbpy'])
37 from IPython.core.debugger import Pdb;
38 ipdb=Pdb()
39 
40 
41 # In[ ]:
42 
43 
44 # when testing a particular flow, load model options from json file, and pass it to model_options
45 # local_prod_jason_file="/home/dongli/fbsource/fbcode/caffe2/caffe2/net_config/33252482/prod_model.json"
46 # with open(local_prod_jason_file, 'r') as f:
47 # prod_model_options = sparse_nn.MODEL_OPTIONS.decode(json.loads(f.read()))
48 # print(prod_model_options)
49 
50 
51 
52 # In[ ]:
53 
54 
55 preproc_options = default_config.DEFAULT_PREPROC_OPTIONS
56 
57 # when testing a particular flow, load model options from json file
58 # load model preproc options from json file
59 # from fblearner.flow.projects.dper.preprocs.ads import build_preproc
60 # local_prod_preproc_jason_file="/home/dongli/fbsource/fbcode/caffe2/caffe2/net_config/33252482/prod_preproc.json"
61 # with open(local_prod_preproc_jason_file, 'r') as f:
62 # prod_preproc_options = build_preproc.options_flow_type.decode(json.loads(f.read()))
63 # print prod_preproc_options
64 
65 # preproc_options = prod_preproc_options
66 
67 
68 # In[ ]:
69 
70 
71 # Finalize config for preprocessor
72 compute_meta.resolve_compute_meta(ads_feature_processor, default_config.DEFAULT_DATASET, preproc_options)
73 print("Done: resolve_compute_meta")
74 
75 
76 # In[ ]:
77 
78 
79 # Assemble the model given preprocessor and model building fuction
80 model = assemble_utils.assemble_model(
81  name='sparse_nn',
82  input_feature_schema=build_preproc.input_feature_schema(
83  preproc_options),
84  trainer_extra_schema=build_preproc.trainer_extra_schema(
85  preproc_options),
86  build_preproc_fun=build_preproc,
87  build_model_fun=sparse_nn.build_model,
88  preproc_options=preproc_options,
89  model_options= default_config.DEFAULT_MODEL_OPTIONS
90 )
91 
92 
93 # In[ ]:
94 
95 
96 # Train model one the given sample dataset
97 estimated_cost = perf_estimator_execution.estimate_perf_locally(model, default_config.DEFAULT_DATASET)
98 print(estimated_cost)
99 
100