質問編集履歴

1

エラーメッセージとソースコードの記入場所を変更しました。

2020/11/11 16:29

投稿

oyakata0702
oyakata0702

スコア0

test CHANGED
File without changes
test CHANGED
@@ -16,15 +16,17 @@
16
16
 
17
17
  エラーメッセージ
18
18
 
19
+ Traceback (most resent call last):
20
+
21
+ File "run_train.py", line 85, in <module>
22
+
23
+ layers = model.build_model(show_model=args.show_architecture)
24
+
25
+ AttributeError: 'function' object has no attribute 'build_model'
26
+
19
27
  ```
20
28
 
21
- Traceback (most resent call last):
29
+
22
-
23
- File "run_train.py", line 85, in <module>
24
-
25
- layers = model.build_model(show_model=args.show_architecture)
26
-
27
- AttributeError: 'function' object has no attribute 'build_model'
28
30
 
29
31
  ### 該当のソースコード
30
32
 
@@ -34,173 +36,175 @@
34
36
 
35
37
  ソースコード
36
38
 
39
+ from __future__ import print_function
40
+
41
+
42
+
43
+ import os
44
+
45
+ try:
46
+
47
+ import cPickle as pickle
48
+
49
+ except ImportError:
50
+
51
+ import pickle
52
+
53
+ import argparse
54
+
55
+
56
+
57
+ from cca_layer.utils.data import load_iapr, load_audio_score
58
+
59
+ from cca_layer.config.settings import EXP_ROOT
60
+
61
+
62
+
63
+ from cca_layer.utils.plotting import BColors
64
+
65
+ col = BColors()
66
+
67
+
68
+
69
+ def select_model(model_path):
70
+
71
+ """ select model and train function """
72
+
73
+
74
+
75
+ model_str = os.path.basename(model_path)
76
+
77
+ print("1", model_str)
78
+
79
+ model_str = model_str.split('.py')[0]
80
+
81
+ exec('from models import ' + model_str + ' as model')
82
+
83
+ print("2", model_str)
84
+
85
+
86
+
87
+ from utils.train_utils import fit
88
+
89
+
90
+
91
+ select_model.EXP_NAME = model_str
92
+
93
+ return select_model, fit
94
+
95
+
96
+
97
+ def select_data(data_name, seed=23):
98
+
99
+ """ select train data """
100
+
101
+
102
+
103
+ if str(data_name) == "iapr":
104
+
105
+ data = load_iapr(seed=seed)
106
+
107
+ elif str(data_name) == "audio_score":
108
+
109
+ data = load_audio_score(seed=seed)
110
+
111
+ else:
112
+
113
+ pass
114
+
115
+
116
+
117
+ return data
118
+
119
+
120
+
121
+
122
+
123
+ if __name__ == '__main__':
124
+
125
+ """ main """
126
+
127
+
128
+
129
+ parser = argparse.ArgumentParser(description='Train multi-modality model.')
130
+
131
+ parser.add_argument('--model', help='select model to train.')
132
+
133
+ parser.add_argument('--data', help='select data for training.')
134
+
135
+ parser.add_argument('--seed', help='query direction.', type=int, default=23)
136
+
137
+ parser.add_argument('--no_dump', help='do not dump model file.', action='store_true')
138
+
139
+ parser.add_argument('--tag', help='add tag to grid search dump file.', type=str, default=None)
140
+
141
+ parser.add_argument('--show_architecture', help='print model architecture.', action='store_true')
142
+
143
+ args = parser.parse_args()
144
+
145
+
146
+
147
+
148
+
149
+ if not os.path.exists(EXP_ROOT):
150
+
151
+ os.makedirs(EXP_ROOT)
152
+
153
+
154
+
155
+ model, fit = select_model(args.model)
156
+
157
+
158
+
159
+ print("\nLoading data...")
160
+
161
+ data = select_data(args.data, args.seed)
162
+
163
+
164
+
165
+ out_path = os.path.join(os.path.join(EXP_ROOT), model.EXP_NAME)
166
+
167
+ dump_file = 'params.pkl' if args.tag is None else 'params_%s.pkl' % args.tag
168
+
169
+ dump_file = os.path.join(out_path, dump_file)
170
+
171
+ log_file = 'results.pkl' if args.tag is None else 'results_%s.pkl' % args.tag
172
+
173
+ log_file = os.path.join(out_path, log_file)
174
+
175
+
176
+
177
+ print("\nBuilding network...")
178
+
179
+ layers = model.build_model(show_model=args.show_architecture) //該当箇所
180
+
181
+
182
+
183
+ dump_file = None if args.no_dump else dump_file
184
+
185
+
186
+
187
+ train_batch_iter = model.train_batch_iterator(model.BATCH_SIZE)
188
+
189
+ valid_batch_iter = model.valid_batch_iterator()
190
+
191
+ layers, va_loss = fit(layers, data, model.objectives,
192
+
193
+ train_batch_iter=train_batch_iterator, valid_batch_iter=valid_batch_iterator,
194
+
195
+ num_epochs=model.MAX_EPOCHS, patience=model.PATIENCE,
196
+
197
+ learn_rate=model.INI_LEARNING_RATE, update_learning_rate=model.update_learning_rate,
198
+
199
+ compute_updates=model.compute_updates, l_2=model.L2, l_1=model.L1,
200
+
201
+ exp_name=model.EXP_NAME, out_path=out_path, dump_file=dump_file, log_file=log_file,
202
+
203
+ refinement_steps=model.REFINEMENT_STEPS, lr_multiplier=model.LR_MULTIPLIER, do_raise=True)
204
+
37
205
  ```
38
206
 
39
- from __future__ import print_function
207
+
40
-
41
-
42
-
43
- import os
44
-
45
- try:
46
-
47
- import cPickle as pickle
48
-
49
- except ImportError:
50
-
51
- import pickle
52
-
53
- import argparse
54
-
55
-
56
-
57
- from cca_layer.utils.data import load_iapr, load_audio_score
58
-
59
- from cca_layer.config.settings import EXP_ROOT
60
-
61
-
62
-
63
- from cca_layer.utils.plotting import BColors
64
-
65
- col = BColors()
66
-
67
-
68
-
69
- def select_model(model_path):
70
-
71
- """ select model and train function """
72
-
73
-
74
-
75
- model_str = os.path.basename(model_path)
76
-
77
- print("1", model_str)
78
-
79
- model_str = model_str.split('.py')[0]
80
-
81
- exec('from models import ' + model_str + ' as model')
82
-
83
- print("2", model_str)
84
-
85
-
86
-
87
- from utils.train_utils import fit
88
-
89
-
90
-
91
- select_model.EXP_NAME = model_str
92
-
93
- return select_model, fit
94
-
95
-
96
-
97
- def select_data(data_name, seed=23):
98
-
99
- """ select train data """
100
-
101
-
102
-
103
- if str(data_name) == "iapr":
104
-
105
- data = load_iapr(seed=seed)
106
-
107
- elif str(data_name) == "audio_score":
108
-
109
- data = load_audio_score(seed=seed)
110
-
111
- else:
112
-
113
- pass
114
-
115
-
116
-
117
- return data
118
-
119
-
120
-
121
-
122
-
123
- if __name__ == '__main__':
124
-
125
- """ main """
126
-
127
-
128
-
129
- parser = argparse.ArgumentParser(description='Train multi-modality model.')
130
-
131
- parser.add_argument('--model', help='select model to train.')
132
-
133
- parser.add_argument('--data', help='select data for training.')
134
-
135
- parser.add_argument('--seed', help='query direction.', type=int, default=23)
136
-
137
- parser.add_argument('--no_dump', help='do not dump model file.', action='store_true')
138
-
139
- parser.add_argument('--tag', help='add tag to grid search dump file.', type=str, default=None)
140
-
141
- parser.add_argument('--show_architecture', help='print model architecture.', action='store_true')
142
-
143
- args = parser.parse_args()
144
-
145
-
146
-
147
-
148
-
149
- if not os.path.exists(EXP_ROOT):
150
-
151
- os.makedirs(EXP_ROOT)
152
-
153
-
154
-
155
- model, fit = select_model(args.model)
156
-
157
-
158
-
159
- print("\nLoading data...")
160
-
161
- data = select_data(args.data, args.seed)
162
-
163
-
164
-
165
- out_path = os.path.join(os.path.join(EXP_ROOT), model.EXP_NAME)
166
-
167
- dump_file = 'params.pkl' if args.tag is None else 'params_%s.pkl' % args.tag
168
-
169
- dump_file = os.path.join(out_path, dump_file)
170
-
171
- log_file = 'results.pkl' if args.tag is None else 'results_%s.pkl' % args.tag
172
-
173
- log_file = os.path.join(out_path, log_file)
174
-
175
-
176
-
177
- print("\nBuilding network...")
178
-
179
- layers = model.build_model(show_model=args.show_architecture) //該当箇所
180
-
181
-
182
-
183
- dump_file = None if args.no_dump else dump_file
184
-
185
-
186
-
187
- train_batch_iter = model.train_batch_iterator(model.BATCH_SIZE)
188
-
189
- valid_batch_iter = model.valid_batch_iterator()
190
-
191
- layers, va_loss = fit(layers, data, model.objectives,
192
-
193
- train_batch_iter=train_batch_iterator, valid_batch_iter=valid_batch_iterator,
194
-
195
- num_epochs=model.MAX_EPOCHS, patience=model.PATIENCE,
196
-
197
- learn_rate=model.INI_LEARNING_RATE, update_learning_rate=model.update_learning_rate,
198
-
199
- compute_updates=model.compute_updates, l_2=model.L2, l_1=model.L1,
200
-
201
- exp_name=model.EXP_NAME, out_path=out_path, dump_file=dump_file, log_file=log_file,
202
-
203
- refinement_steps=model.REFINEMENT_STEPS, lr_multiplier=model.LR_MULTIPLIER, do_raise=True)
204
208
 
205
209
  ### 試したこと
206
210