这是我在完成教程并尝试使用我自己的数据集构建一个 tfx 管道之后第一次构建一个 tfx 管道。我可以对我编写的转换代码使用一些建议,并且更好地理解,我会感谢您的时间并提前感谢。
我已经完成了 ExampleGen、StatisticsGen、SchemaGen、ExampleValidator、Transform,并且在 Trainer 组件中出现错误。
错误:
c:\lib\site-packages\tfx\orchestration\launcher\in_process_component_launcher.py in _run_executor(self, execution_id, input_dict, output_dict, exec_properties)
65 executor_context) # type: ignore
66
---> 67 executor.Do(input_dict, output_dict, exec_properties)
c:\lib\site-packages\tfx\components\trainer\executor.py in Do(self, input_dict, output_dict, exec_properties)
317
318 fn_args = self._GetFnArgs(input_dict, output_dict, exec_properties)
--> 319 trainer_fn = self._GetFn(exec_properties, 'trainer_fn')
320
321 schema = io_utils.parse_pbtxt_file(fn_args.schema_file, schema_pb2.Schema())
c:\lib\site-packages\tfx\components\trainer\executor.py in _GetFn(self, exec_properties, fn_name)
128 if has_module_file:
129 return import_utils.import_func_from_source(
--> 130 exec_properties['module_file'], fn_name)
131
132 fn_path_split = exec_properties[fn_name].split('.')
c:\lib\site-packages\tfx\utils\import_utils.py in import_func_from_source(source_path, fn_name)
66 user_module = types.ModuleType(loader.name)
67 loader.exec_module(user_module)
---> 68 return getattr(user_module, fn_name)
69
70 except IOError:
AttributeError: module 'user_module' has no attribute 'trainer_fn'
代码:
def get_model(show_summary=True):
#one-hot categorical features
num_A = 4,
num_B = 3,
num_C = 2,
num_D = 8,
num_E = 12,
num_F = 4,
num_G = 16,
num_H = 26
input_A = tf.keras.Input(shape=(num_A,), name="A_xf")
input_B = tf.keras.Input(shape=(num_B,), name="B_xf")
input_C = tf.keras.Input(shape=(num_C,), name="C_xf")
input_D = tf.keras.Input(shape=(num_D,), name="D_xf")
input_E = tf.keras.Input(shape=(num_E,), name="E_xf")
input_F = tf.keras.Input(shape=(num_F,), name="F_xf")
input_G = tf.keras.Input(shape=(num_G,), name="G_xf")
input_H = tf.keras.Input(shape=(num_H,), name="H_xf")
fl = keras.Input(shape=(75,))
dense = layers.Dense(35, activation = "relu")
x = dense(fl)
x = layers.Dense(15, activation="relu")(x)
outputs = layers.Dense(1, activation="sigmoid")(x)
_inputs = [input_A, input_B, input_C, input_D, input_E, input_F, input_G, input_H]
model = keras.Model(inputs=inputs, outputs=outputs)
model.compile(optimizer='rmsprop',
loss='binary_crossentropy',
metrics=['accuracy'])
if show_summary:
model.summary()
return model