tensorflow2.0tensorflow-transformtfx

Trainer Component Error in Tensorflow Extension


it is my first time building a tfx pipeline after I went through the tutorials and trying to build one with my own dataset. I could use some advice on the transform code that I wrote, and understand better, I'd appreciate your time and thanks in advance.

I've done the ExampleGen, StatisticsGen, SchemaGen, ExampleValidator, Transform, and having error in Trainer components.

ERROR:

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'

CODE:

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

Solution

  • By using the directions and comment by Jason, I've changed up the model part as tfx doesn't support the sequential model but the Keras functional API.

    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")
    
    inputs_con = tf.keras.layers.concatenate([
    input_A,
    input_B,
    input_C,
    input_D,
    input_E,
    input_F,
    input_G,
    input_H])
    
    dense_1 = tf.keras.layers.Dense(50, activation = 'relu')(inputs_con)
    dense_2 = tf keras.layers.Dense(25, activation = "rely") (dense_1)
    output = tf.keras.laters.Dense(1, activation = "sigmoid") (dense_2)
    model = keras.Model(inputs=inputs, outputs=outputs)
    
    _inputs = [
    input_A,
    input_B,
    input_C,
    input_D,
    input_E,
    input_F,
    input_G,
    input_H]
    
    model = tf.keras.models.Model(_inputs, output)
    
    model.compile(optimizer='rmsprop',
              loss='binary_crossentropy',
              metrics=['accuracy'])
    
    if show_summary:
        model.summary()
    
    return model