Repository: tensorflow/model-analysis
Issue: Bug: module 'tfx_bsl.coders.example_coder' has no attribute 'ExampleToNumpyDict'
Root cause: Environment Incompatibility

### System information

-   **Have I written custom code (Yes)**:
-   **OS Platform and Distribution (Docker of Jupyter)**:
-   **TensorFlow Model Analysis installed from (pip install)**:
-   **TensorFlow Model Analysis version (0.21.6)**:
-   **Python version**:  3.7.6
-   **Jupyter Notebook version**: 6.0.3
-   **Exact command to reproduce**: as shown below.

### Describe the problem

I've tried the emaples [here](https://www.tensorflow.org/tfx/tutorials/model_analysis/tfma_basic#install_jupyter_extensions), and all works well in jupyter except `tfma.view.render_time_series` doesn't show anything.

So, I tried tfma on my own `keras saved model`.  Model info is inspected using saved_model_cli command.

`saved_model_cli show --dir xdeepfm --tag_set serve --signature_def serving_default`

```
The given SavedModel SignatureDef contains the following input(s):
  inputs['input_1'] tensor_info:
      dtype: DT_INT64
      shape: (-1, 31)
      name: serving_default_input_1:0
The given SavedModel SignatureDef contains the following output(s):
  outputs['output_1'] tensor_info:
      dtype: DT_FLOAT
      shape: (-1, 1)
      name: StatefulPartitionedCall:0
Method name is: tensorflow/serving/predict
```

With the codes below,  some errors occur when `run_model_analysis` is called. It's a AttributeError: `module 'tfx_bsl.coders.example_coder' has no attribute 'ExampleToNumpyDict'`. 

The version of tfx_bsl in my system is `0.21.4`, and I've checked the source code [here](https://github.com/tensorflow/tfx-bsl/blob/v0.21.4/tfx_bsl/coders/example_coder.py). It does have the `ExampleToNumpyDict` : `from tfx_bsl.cc.tfx_bsl_extension.coders import ExampleToNumpyDict`.

So are there some errors in my code? Or something else? Thank for your help~

### Source code / logs

**Code**

```python
import tensorflow as tf
import tensorflow_model_analysis as tfma
import os
import numpy as np
from tensorflow.core.example import example_pb2
from google.protobuf import text_format

BASE_DIR = '/home/jovyan/work'
TFMA_DIR = os.path.join(BASE_DIR, 'tfma')
OUTPUT_DIR = os.path.join(TFMA_DIR, 'output')

SAMPLE_SIZE=100
inputs = np.random.randint(1001, size=(SAMPLE_SIZE, 31))
labels = np.random.randint(2, size=(SAMPLE_SIZE, 1))

examples = []
for i in range(SAMPLE_SIZE):
    example = example_pb2.Example()
    example.features.feature['input_1'].int64_list.value[:] = inputs[i].tolist()
    example.features.feature['output_1'].int64_list.value[:] = labels[i].tolist()
    examples.append(example)

TFRecord_file = os.path.join(TFMA_DIR, 'train_data.rio')
with tf.io.TFRecordWriter(TFRecord_file) as writer:
    for example in examples:
        writer.write(example.SerializeToString())
    writer.flush()
    writer.close()

eval_config = text_format.Parse("""
  model_specs {
    # This assumes a serving model with a "serving_default" signature.
    label_key: "output_1"
    # example_weight_key: "weight"
  }
  metrics_specs {
    # This assumes a binary classification model.
    # metrics { class_name: "AUC" }
    # ... other metrics ...
  }
  slicing_specs {}
""", tfma.EvalConfig())

eval_model_dir = os.path.join(TFMA_DIR, 'xdeepfm')
print(eval_model_dir)
eval_model = tfma.default_eval_shared_model(eval_saved_model_path=eval_model_dir,eval_config=eval_config)
eval_result = tfma.run_model_analysis(eval_shared_model=eval_model,
                                      data_location=TFRecord_file,
                                      file_format='tfrecords',
                                      output_path=OUTPUT_DIR,
                                      extractors=None)
tfma.view.render_slicing_metrics(eval_result)
```

**Logs**

```
/opt/conda/lib/python3.7/site-packages/apache_beam/transforms/core.py in <lambda>(x, *args, **kwargs)
   1434   if _fn_takes_side_inputs(fn):
-> 1435     wrapper = lambda x, *args, **kwargs: [fn(x, *args, **kwargs)]
   1436   else:

/opt/conda/lib/python3.7/site-packages/tensorflow_model_analysis/extractors/input_extractor.py in _ParseExample(extracts, eval_config)
    104 
--> 105   features = example_coder.ExampleToNumpyDict(extracts[constants.INPUT_KEY])
    106   extracts = copy.copy(extracts)

AttributeError: module 'tfx_bsl.coders.example_coder' has no attribute 'ExampleToNumpyDict'
```


@brills, could this be caused by the following:

https://github.com/tensorflow/tfx-bsl/blob/v0.21.4/tfx_bsl/coders/example_coder.py#L30

That should be what happened, but the root cause was that tfx_bsl's extension module was not imported correctly, which was most likely caused by a wrong pyarrow version.

@AlexanderJLiu, in the same piece of code, could you do

```
import pyarrow as pa
print(pa.__version__)
```
?


@brills @mdreves Yes, it's the wrong `pyarrow version` causes this problem. The version of `pyarrow` in my system is `0.16.0` which is compatible with tfma (requires `pyarrow>=0.15,<1`) but not with tfx-bsl (requires `pyarrow>=0.15.0,<0.16.0`). So I fixed this by reinstalled pyarrow of version `0.15.1`: `pip install pyarrow==0.15.1`. Thanks~

@brills 
By the way, I've got another problem with the same code when `run_model_analysis` is called. It's a Runtime error about input tensor: `input #0(zero-based) was expected to be a int64 tensor but is a int32 tensor`. 
The TFRecord file I used is generated with `example.features.feature['input_1'].int64_list.value[:] = inputs[i].tolist()`  is compatible with the model `inputs['input_1'] tensor_info: dtype: DT_INT64`.  I've also change the dtpye of inputs array with `int64`: `inputs = np.random.randint(1001, size=(SAMPLE_SIZE, 31), dtype='int64')` and still get the same error. 
So, I don't know where the problem is, and look forward to your help. Thanks~
```
/opt/conda/lib/python3.7/site-packages/tensorflow_core/python/eager/execute.py in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
     65     else:
     66       message = e.message
---> 67     six.raise_from(core._status_to_exception(e.code, message), None)
     68   except TypeError as e:
     69     keras_symbolic_tensors = [

/opt/conda/lib/python3.7/site-packages/six.py in raise_from(value, from_value)

RuntimeError: tensorflow.python.framework.errors_impl.InvalidArgumentError: cannot compute __inference_signature_wrapper_60219 as input #0(zero-based) was expected to be a int64 tensor but is a int32 tensor [Op:__inference_signature_wrapper_60219] [while running 'ExtractEvaluateAndWriteResults/ExtractAndEvaluate/ExtractPredictions/Predict']
```