In this colab notebook, you will use Fairness Indicators to explore the Smiling
attribute in a large-scale face image dataset. Fairness Indicators is a suite of tools built on top of TensorFlow Model Analysis that enable regular evaluation of fairness metrics in product pipelines. This Introductory Video provides more details and context on the real-world scenario presented here, one of primary motivations for creating Fairness Indicators. This notebook will teach you to:
Credits: Some of the code and discussions are taken from this Tensorflow tutorial.
This will install all related libraries such as TFMA and TFDV.
# Install this package to use Colab's GPU for training
!apt install --allow-change-held-packages libcudnn8=8.4.1.50-1+cuda11.6
Reading package lists... Done Building dependency tree Reading state information... Done The following package was automatically installed and is no longer required: libnvidia-common-460 Use 'apt autoremove' to remove it. The following packages will be REMOVED: libcudnn8-dev The following held packages will be changed: libcudnn8 The following packages will be upgraded: libcudnn8 1 upgraded, 0 newly installed, 1 to remove and 18 not upgraded. Need to get 420 MB of archives. After this operation, 3,369 MB disk space will be freed. Get:1 https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64 libcudnn8 8.4.1.50-1+cuda11.6 [420 MB] Fetched 420 MB in 13s (32.0 MB/s) (Reading database ... 155685 files and directories currently installed.) Removing libcudnn8-dev (8.0.5.39-1+cuda11.1) ... (Reading database ... 155663 files and directories currently installed.) Preparing to unpack .../libcudnn8_8.4.1.50-1+cuda11.6_amd64.deb ... Unpacking libcudnn8 (8.4.1.50-1+cuda11.6) over (8.0.5.39-1+cuda11.1) ... Setting up libcudnn8 (8.4.1.50-1+cuda11.6) ...
!pip install --use-deprecated=legacy-resolver fairness-indicators
!pip install apache-beam==2.39.0
Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/
Collecting fairness-indicators
Downloading fairness_indicators-0.40.0-py3-none-any.whl (24 kB)
Collecting tensorflow!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,<3,>=1.15.5
Downloading tensorflow-2.9.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (511.8 MB)
|████████████████████████████████| 511.8 MB 7.8 kB/s
Requirement already satisfied: protobuf<4,>=3.13 in /usr/local/lib/python3.7/dist-packages (from fairness-indicators) (3.17.3)
Collecting witwidget<2,>=1.4.4
Downloading witwidget-1.8.1-py3-none-any.whl (1.5 MB)
|████████████████████████████████| 1.5 MB 46.0 MB/s
Collecting tensorflow-model-analysis<0.41,>=0.40
Downloading tensorflow_model_analysis-0.40.0-py3-none-any.whl (1.8 MB)
|████████████████████████████████| 1.8 MB 54.9 MB/s
Collecting tensorflow-data-validation<1.10.0,>=1.9.0
Downloading tensorflow_data_validation-1.9.0-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.5 MB)
|████████████████████████████████| 1.5 MB 51.7 MB/s
Requirement already satisfied: tensorflow-hub<1.0.0,>=0.8.0 in /usr/local/lib/python3.7/dist-packages (from fairness-indicators) (0.12.0)
Requirement already satisfied: google-pasta>=0.1.1 in /usr/local/lib/python3.7/dist-packages (from tensorflow!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,<3,>=1.15.5->fairness-indicators) (0.2.0)
Requirement already satisfied: numpy>=1.20 in /usr/local/lib/python3.7/dist-packages (from tensorflow!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,<3,>=1.15.5->fairness-indicators) (1.21.6)
Requirement already satisfied: astunparse>=1.6.0 in /usr/local/lib/python3.7/dist-packages (from tensorflow!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,<3,>=1.15.5->fairness-indicators) (1.6.3)
Requirement already satisfied: opt-einsum>=2.3.2 in /usr/local/lib/python3.7/dist-packages (from tensorflow!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,<3,>=1.15.5->fairness-indicators) (3.3.0)
Collecting flatbuffers<2,>=1.12
Downloading flatbuffers-1.12-py2.py3-none-any.whl (15 kB)
Requirement already satisfied: grpcio<2.0,>=1.24.3 in /usr/local/lib/python3.7/dist-packages (from tensorflow!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,<3,>=1.15.5->fairness-indicators) (1.47.0)
Requirement already satisfied: h5py>=2.9.0 in /usr/local/lib/python3.7/dist-packages (from tensorflow!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,<3,>=1.15.5->fairness-indicators) (3.1.0)
Collecting gast<=0.4.0,>=0.2.1
Downloading gast-0.4.0-py3-none-any.whl (9.8 kB)
Collecting keras<2.10.0,>=2.9.0rc0
Downloading keras-2.9.0-py2.py3-none-any.whl (1.6 MB)
|████████████████████████████████| 1.6 MB 45.4 MB/s
Requirement already satisfied: termcolor>=1.1.0 in /usr/local/lib/python3.7/dist-packages (from tensorflow!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,<3,>=1.15.5->fairness-indicators) (1.1.0)
Requirement already satisfied: keras-preprocessing>=1.1.1 in /usr/local/lib/python3.7/dist-packages (from tensorflow!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,<3,>=1.15.5->fairness-indicators) (1.1.2)
Requirement already satisfied: typing-extensions>=3.6.6 in /usr/local/lib/python3.7/dist-packages (from tensorflow!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,<3,>=1.15.5->fairness-indicators) (4.1.1)
Requirement already satisfied: absl-py>=1.0.0 in /usr/local/lib/python3.7/dist-packages (from tensorflow!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,<3,>=1.15.5->fairness-indicators) (1.2.0)
Requirement already satisfied: six>=1.12.0 in /usr/local/lib/python3.7/dist-packages (from tensorflow!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,<3,>=1.15.5->fairness-indicators) (1.15.0)
Requirement already satisfied: packaging in /usr/local/lib/python3.7/dist-packages (from tensorflow!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,<3,>=1.15.5->fairness-indicators) (21.3)
Collecting tensorboard<2.10,>=2.9
Downloading tensorboard-2.9.1-py3-none-any.whl (5.8 MB)
|████████████████████████████████| 5.8 MB 52.2 MB/s
Requirement already satisfied: libclang>=13.0.0 in /usr/local/lib/python3.7/dist-packages (from tensorflow!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,<3,>=1.15.5->fairness-indicators) (14.0.6)
Requirement already satisfied: tensorflow-io-gcs-filesystem>=0.23.1 in /usr/local/lib/python3.7/dist-packages (from tensorflow!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,<3,>=1.15.5->fairness-indicators) (0.26.0)
Requirement already satisfied: setuptools in /usr/local/lib/python3.7/dist-packages (from tensorflow!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,<3,>=1.15.5->fairness-indicators) (57.4.0)
Requirement already satisfied: wrapt>=1.11.0 in /usr/local/lib/python3.7/dist-packages (from tensorflow!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,<3,>=1.15.5->fairness-indicators) (1.14.1)
Collecting tensorflow-estimator<2.10.0,>=2.9.0rc0
Downloading tensorflow_estimator-2.9.0-py2.py3-none-any.whl (438 kB)
|████████████████████████████████| 438 kB 59.5 MB/s
Requirement already satisfied: google-api-python-client>=1.7.8 in /usr/local/lib/python3.7/dist-packages (from witwidget<2,>=1.4.4->fairness-indicators) (1.12.11)
Requirement already satisfied: ipywidgets>=7.0.0 in /usr/local/lib/python3.7/dist-packages (from witwidget<2,>=1.4.4->fairness-indicators) (7.7.1)
Requirement already satisfied: oauth2client>=4.1.3 in /usr/local/lib/python3.7/dist-packages (from witwidget<2,>=1.4.4->fairness-indicators) (4.1.3)
Collecting apache-beam[gcp]<3,>=2.38
Downloading apache_beam-2.41.0-cp37-cp37m-manylinux2010_x86_64.whl (10.9 MB)
|████████████████████████████████| 10.9 MB 36.7 MB/s
Collecting tfx-bsl<1.10.0,>=1.9.0
Downloading tfx_bsl-1.9.0-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (19.2 MB)
|████████████████████████████████| 19.2 MB 1.1 MB/s
Collecting pyarrow<6,>=1
Downloading pyarrow-5.0.0-cp37-cp37m-manylinux2014_x86_64.whl (23.6 MB)
|████████████████████████████████| 23.6 MB 1.3 MB/s
Requirement already satisfied: pandas<2,>=1.0 in /usr/local/lib/python3.7/dist-packages (from tensorflow-model-analysis<0.41,>=0.40->fairness-indicators) (1.3.5)
Requirement already satisfied: scipy<2,>=1.4.1 in /usr/local/lib/python3.7/dist-packages (from tensorflow-model-analysis<0.41,>=0.40->fairness-indicators) (1.7.3)
Collecting tensorflow-metadata<1.10.0,>=1.9.0
Downloading tensorflow_metadata-1.9.0-py3-none-any.whl (51 kB)
|████████████████████████████████| 51 kB 7.8 MB/s
Requirement already satisfied: ipython<8,>=7 in /usr/local/lib/python3.7/dist-packages (from tensorflow-model-analysis<0.41,>=0.40->fairness-indicators) (7.9.0)
Collecting joblib<0.15,>=0.12
Downloading joblib-0.14.1-py2.py3-none-any.whl (294 kB)
|████████████████████████████████| 294 kB 70.5 MB/s
Collecting pyfarmhash<0.4,>=0.2
Downloading pyfarmhash-0.3.2.tar.gz (99 kB)
|████████████████████████████████| 99 kB 10.9 MB/s
Requirement already satisfied: wheel<1.0,>=0.23.0 in /usr/local/lib/python3.7/dist-packages (from astunparse>=1.6.0->tensorflow!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,<3,>=1.15.5->fairness-indicators) (0.37.1)
Requirement already satisfied: cached-property; python_version < "3.8" in /usr/local/lib/python3.7/dist-packages (from h5py>=2.9.0->tensorflow!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,<3,>=1.15.5->fairness-indicators) (1.5.2)
Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in /usr/local/lib/python3.7/dist-packages (from packaging->tensorflow!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,<3,>=1.15.5->fairness-indicators) (3.0.9)
Requirement already satisfied: requests<3,>=2.21.0 in /usr/local/lib/python3.7/dist-packages (from tensorboard<2.10,>=2.9->tensorflow!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,<3,>=1.15.5->fairness-indicators) (2.23.0)
Requirement already satisfied: google-auth-oauthlib<0.5,>=0.4.1 in /usr/local/lib/python3.7/dist-packages (from tensorboard<2.10,>=2.9->tensorflow!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,<3,>=1.15.5->fairness-indicators) (0.4.6)
Requirement already satisfied: tensorboard-data-server<0.7.0,>=0.6.0 in /usr/local/lib/python3.7/dist-packages (from tensorboard<2.10,>=2.9->tensorflow!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,<3,>=1.15.5->fairness-indicators) (0.6.1)
Requirement already satisfied: werkzeug>=1.0.1 in /usr/local/lib/python3.7/dist-packages (from tensorboard<2.10,>=2.9->tensorflow!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,<3,>=1.15.5->fairness-indicators) (1.0.1)
Requirement already satisfied: tensorboard-plugin-wit>=1.6.0 in /usr/local/lib/python3.7/dist-packages (from tensorboard<2.10,>=2.9->tensorflow!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,<3,>=1.15.5->fairness-indicators) (1.8.1)
Requirement already satisfied: markdown>=2.6.8 in /usr/local/lib/python3.7/dist-packages (from tensorboard<2.10,>=2.9->tensorflow!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,<3,>=1.15.5->fairness-indicators) (3.4.1)
Requirement already satisfied: google-auth<3,>=1.6.3 in /usr/local/lib/python3.7/dist-packages (from tensorboard<2.10,>=2.9->tensorflow!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,<3,>=1.15.5->fairness-indicators) (1.35.0)
Requirement already satisfied: httplib2<1dev,>=0.15.0 in /usr/local/lib/python3.7/dist-packages (from google-api-python-client>=1.7.8->witwidget<2,>=1.4.4->fairness-indicators) (0.17.4)
Requirement already satisfied: google-api-core<3dev,>=1.21.0; python_version >= "3" in /usr/local/lib/python3.7/dist-packages (from google-api-python-client>=1.7.8->witwidget<2,>=1.4.4->fairness-indicators) (1.31.6)
Requirement already satisfied: google-auth-httplib2>=0.0.3 in /usr/local/lib/python3.7/dist-packages (from google-api-python-client>=1.7.8->witwidget<2,>=1.4.4->fairness-indicators) (0.0.4)
Requirement already satisfied: uritemplate<4dev,>=3.0.0 in /usr/local/lib/python3.7/dist-packages (from google-api-python-client>=1.7.8->witwidget<2,>=1.4.4->fairness-indicators) (3.0.1)
Requirement already satisfied: traitlets>=4.3.1 in /usr/local/lib/python3.7/dist-packages (from ipywidgets>=7.0.0->witwidget<2,>=1.4.4->fairness-indicators) (5.1.1)
Requirement already satisfied: jupyterlab-widgets>=1.0.0; python_version >= "3.6" in /usr/local/lib/python3.7/dist-packages (from ipywidgets>=7.0.0->witwidget<2,>=1.4.4->fairness-indicators) (3.0.2)
Requirement already satisfied: widgetsnbextension~=3.6.0 in /usr/local/lib/python3.7/dist-packages (from ipywidgets>=7.0.0->witwidget<2,>=1.4.4->fairness-indicators) (3.6.1)
Requirement already satisfied: ipython-genutils~=0.2.0 in /usr/local/lib/python3.7/dist-packages (from ipywidgets>=7.0.0->witwidget<2,>=1.4.4->fairness-indicators) (0.2.0)
Requirement already satisfied: ipykernel>=4.5.1 in /usr/local/lib/python3.7/dist-packages (from ipywidgets>=7.0.0->witwidget<2,>=1.4.4->fairness-indicators) (5.3.4)
Requirement already satisfied: pyasn1-modules>=0.0.5 in /usr/local/lib/python3.7/dist-packages (from oauth2client>=4.1.3->witwidget<2,>=1.4.4->fairness-indicators) (0.2.8)
Requirement already satisfied: pyasn1>=0.1.7 in /usr/local/lib/python3.7/dist-packages (from oauth2client>=4.1.3->witwidget<2,>=1.4.4->fairness-indicators) (0.4.8)
Requirement already satisfied: rsa>=3.1.4 in /usr/local/lib/python3.7/dist-packages (from oauth2client>=4.1.3->witwidget<2,>=1.4.4->fairness-indicators) (4.9)
Requirement already satisfied: pydot<2,>=1.2.0 in /usr/local/lib/python3.7/dist-packages (from apache-beam[gcp]<3,>=2.38->tensorflow-model-analysis<0.41,>=0.40->fairness-indicators) (1.3.0)
Collecting proto-plus<2,>=1.7.1
Downloading proto_plus-1.22.1-py3-none-any.whl (47 kB)
|████████████████████████████████| 47 kB 5.3 MB/s
Collecting hdfs<3.0.0,>=2.1.0
Downloading hdfs-2.7.0-py3-none-any.whl (34 kB)
Collecting fastavro<2,>=0.23.6
Downloading fastavro-1.6.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.4 MB)
|████████████████████████████████| 2.4 MB 48.0 MB/s
Collecting orjson<4.0
Downloading orjson-3.8.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (270 kB)
|████████████████████████████████| 270 kB 66.8 MB/s
Requirement already satisfied: python-dateutil<3,>=2.8.0 in /usr/local/lib/python3.7/dist-packages (from apache-beam[gcp]<3,>=2.38->tensorflow-model-analysis<0.41,>=0.40->fairness-indicators) (2.8.2)
Requirement already satisfied: crcmod<2.0,>=1.7 in /usr/local/lib/python3.7/dist-packages (from apache-beam[gcp]<3,>=2.38->tensorflow-model-analysis<0.41,>=0.40->fairness-indicators) (1.7)
Requirement already satisfied: pytz>=2018.3 in /usr/local/lib/python3.7/dist-packages (from apache-beam[gcp]<3,>=2.38->tensorflow-model-analysis<0.41,>=0.40->fairness-indicators) (2022.2.1)
Collecting dill<0.3.2,>=0.3.1.1
Downloading dill-0.3.1.1.tar.gz (151 kB)
|████████████████████████████████| 151 kB 75.2 MB/s
Collecting pymongo<4.0.0,>=3.8.0
Downloading pymongo-3.12.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (508 kB)
|████████████████████████████████| 508 kB 70.8 MB/s
Collecting cloudpickle<3,>=2.1.0
Downloading cloudpickle-2.1.0-py3-none-any.whl (25 kB)
Collecting google-cloud-pubsub<3,>=2.1.0; extra == "gcp"
Downloading google_cloud_pubsub-2.13.6-py2.py3-none-any.whl (235 kB)
|████████████████████████████████| 235 kB 52.5 MB/s
Requirement already satisfied: google-cloud-datastore<2,>=1.8.0; extra == "gcp" in /usr/local/lib/python3.7/dist-packages (from apache-beam[gcp]<3,>=2.38->tensorflow-model-analysis<0.41,>=0.40->fairness-indicators) (1.8.0)
Collecting grpcio-gcp<1,>=0.2.2; extra == "gcp"
Downloading grpcio_gcp-0.2.2-py2.py3-none-any.whl (9.4 kB)
Collecting google-cloud-bigtable<2,>=0.31.1; extra == "gcp"
Downloading google_cloud_bigtable-1.7.2-py2.py3-none-any.whl (267 kB)
|████████████████████████████████| 267 kB 72.8 MB/s
Collecting google-cloud-recommendations-ai<0.8.0,>=0.1.0; extra == "gcp"
Downloading google_cloud_recommendations_ai-0.7.1-py2.py3-none-any.whl (148 kB)
|████████████████████████████████| 148 kB 74.8 MB/s
Requirement already satisfied: google-cloud-bigquery<3,>=1.6.0; extra == "gcp" in /usr/local/lib/python3.7/dist-packages (from apache-beam[gcp]<3,>=2.38->tensorflow-model-analysis<0.41,>=0.40->fairness-indicators) (1.21.0)
Requirement already satisfied: cachetools<5,>=3.1.0; extra == "gcp" in /usr/local/lib/python3.7/dist-packages (from apache-beam[gcp]<3,>=2.38->tensorflow-model-analysis<0.41,>=0.40->fairness-indicators) (4.2.4)
Collecting google-cloud-spanner<2,>=1.13.0; extra == "gcp"
Downloading google_cloud_spanner-1.19.3-py2.py3-none-any.whl (255 kB)
|████████████████████████████████| 255 kB 72.7 MB/s
Collecting google-cloud-vision<2,>=0.38.0; extra == "gcp"
Downloading google_cloud_vision-1.0.2-py2.py3-none-any.whl (435 kB)
|████████████████████████████████| 435 kB 70.9 MB/s
Collecting google-cloud-bigquery-storage<2.14,>=2.6.3; extra == "gcp"
Downloading google_cloud_bigquery_storage-2.13.2-py2.py3-none-any.whl (180 kB)
|████████████████████████████████| 180 kB 73.6 MB/s
Collecting google-cloud-language<2,>=1.3.0; extra == "gcp"
Downloading google_cloud_language-1.3.2-py2.py3-none-any.whl (83 kB)
|████████████████████████████████| 83 kB 2.2 MB/s
Collecting google-apitools<0.5.32,>=0.5.31; extra == "gcp"
Downloading google-apitools-0.5.31.tar.gz (173 kB)
|████████████████████████████████| 173 kB 75.3 MB/s
Collecting google-cloud-videointelligence<2,>=1.8.0; extra == "gcp"
Downloading google_cloud_videointelligence-1.16.3-py2.py3-none-any.whl (183 kB)
|████████████████████████████████| 183 kB 66.3 MB/s
Collecting google-cloud-dlp<4,>=3.0.0; extra == "gcp"
Downloading google_cloud_dlp-3.8.1-py2.py3-none-any.whl (119 kB)
|████████████████████████████████| 119 kB 75.5 MB/s
Requirement already satisfied: google-cloud-core<3,>=0.28.1; extra == "gcp" in /usr/local/lib/python3.7/dist-packages (from apache-beam[gcp]<3,>=2.38->tensorflow-model-analysis<0.41,>=0.40->fairness-indicators) (1.0.3)
Collecting google-cloud-pubsublite<2,>=1.2.0; extra == "gcp"
Downloading google_cloud_pubsublite-1.4.3-py2.py3-none-any.whl (267 kB)
|████████████████████████████████| 267 kB 66.1 MB/s
Collecting tensorflow-serving-api!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,<3,>=1.15
Downloading tensorflow_serving_api-2.9.1-py2.py3-none-any.whl (37 kB)
Requirement already satisfied: googleapis-common-protos<2,>=1.52.0 in /usr/local/lib/python3.7/dist-packages (from tensorflow-metadata<1.10.0,>=1.9.0->tensorflow-model-analysis<0.41,>=0.40->fairness-indicators) (1.56.4)
Requirement already satisfied: pexpect; sys_platform != "win32" in /usr/local/lib/python3.7/dist-packages (from ipython<8,>=7->tensorflow-model-analysis<0.41,>=0.40->fairness-indicators) (4.8.0)
Requirement already satisfied: decorator in /usr/local/lib/python3.7/dist-packages (from ipython<8,>=7->tensorflow-model-analysis<0.41,>=0.40->fairness-indicators) (4.4.2)
Requirement already satisfied: prompt-toolkit<2.1.0,>=2.0.0 in /usr/local/lib/python3.7/dist-packages (from ipython<8,>=7->tensorflow-model-analysis<0.41,>=0.40->fairness-indicators) (2.0.10)
Requirement already satisfied: pickleshare in /usr/local/lib/python3.7/dist-packages (from ipython<8,>=7->tensorflow-model-analysis<0.41,>=0.40->fairness-indicators) (0.7.5)
Requirement already satisfied: pygments in /usr/local/lib/python3.7/dist-packages (from ipython<8,>=7->tensorflow-model-analysis<0.41,>=0.40->fairness-indicators) (2.6.1)
Requirement already satisfied: backcall in /usr/local/lib/python3.7/dist-packages (from ipython<8,>=7->tensorflow-model-analysis<0.41,>=0.40->fairness-indicators) (0.2.0)
Collecting jedi>=0.10
Downloading jedi-0.18.1-py2.py3-none-any.whl (1.6 MB)
|████████████████████████████████| 1.6 MB 54.3 MB/s
Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests<3,>=2.21.0->tensorboard<2.10,>=2.9->tensorflow!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,<3,>=1.15.5->fairness-indicators) (2.10)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.7/dist-packages (from requests<3,>=2.21.0->tensorboard<2.10,>=2.9->tensorflow!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,<3,>=1.15.5->fairness-indicators) (1.24.3)
Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.7/dist-packages (from requests<3,>=2.21.0->tensorboard<2.10,>=2.9->tensorflow!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,<3,>=1.15.5->fairness-indicators) (3.0.4)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests<3,>=2.21.0->tensorboard<2.10,>=2.9->tensorflow!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,<3,>=1.15.5->fairness-indicators) (2022.6.15)
Requirement already satisfied: requests-oauthlib>=0.7.0 in /usr/local/lib/python3.7/dist-packages (from google-auth-oauthlib<0.5,>=0.4.1->tensorboard<2.10,>=2.9->tensorflow!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,<3,>=1.15.5->fairness-indicators) (1.3.1)
Requirement already satisfied: importlib-metadata>=4.4; python_version < "3.10" in /usr/local/lib/python3.7/dist-packages (from markdown>=2.6.8->tensorboard<2.10,>=2.9->tensorflow!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,<3,>=1.15.5->fairness-indicators) (4.12.0)
Requirement already satisfied: notebook>=4.4.1 in /usr/local/lib/python3.7/dist-packages (from widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->witwidget<2,>=1.4.4->fairness-indicators) (5.3.1)
Requirement already satisfied: tornado>=4.2 in /usr/local/lib/python3.7/dist-packages (from ipykernel>=4.5.1->ipywidgets>=7.0.0->witwidget<2,>=1.4.4->fairness-indicators) (5.1.1)
Requirement already satisfied: jupyter-client in /usr/local/lib/python3.7/dist-packages (from ipykernel>=4.5.1->ipywidgets>=7.0.0->witwidget<2,>=1.4.4->fairness-indicators) (6.1.12)
Collecting docopt
Downloading docopt-0.6.2.tar.gz (25 kB)
Collecting grpc-google-iam-v1<1.0.0dev,>=0.12.4
Downloading grpc_google_iam_v1-0.12.4-py2.py3-none-any.whl (26 kB)
Collecting grpcio-status>=1.16.0
Downloading grpcio_status-1.48.1-py3-none-any.whl (14 kB)
Requirement already satisfied: google-resumable-media!=0.4.0,<0.5.0dev,>=0.3.1 in /usr/local/lib/python3.7/dist-packages (from google-cloud-bigquery<3,>=1.6.0; extra == "gcp"->apache-beam[gcp]<3,>=2.38->tensorflow-model-analysis<0.41,>=0.40->fairness-indicators) (0.4.1)
Collecting fasteners>=0.14
Downloading fasteners-0.17.3-py3-none-any.whl (18 kB)
Collecting overrides<7.0.0,>=6.0.1
Downloading overrides-6.2.0-py3-none-any.whl (17 kB)
Requirement already satisfied: ptyprocess>=0.5 in /usr/local/lib/python3.7/dist-packages (from pexpect; sys_platform != "win32"->ipython<8,>=7->tensorflow-model-analysis<0.41,>=0.40->fairness-indicators) (0.7.0)
Requirement already satisfied: wcwidth in /usr/local/lib/python3.7/dist-packages (from prompt-toolkit<2.1.0,>=2.0.0->ipython<8,>=7->tensorflow-model-analysis<0.41,>=0.40->fairness-indicators) (0.2.5)
Requirement already satisfied: parso<0.9.0,>=0.8.0 in /usr/local/lib/python3.7/dist-packages (from jedi>=0.10->ipython<8,>=7->tensorflow-model-analysis<0.41,>=0.40->fairness-indicators) (0.8.3)
Requirement already satisfied: oauthlib>=3.0.0 in /usr/local/lib/python3.7/dist-packages (from requests-oauthlib>=0.7.0->google-auth-oauthlib<0.5,>=0.4.1->tensorboard<2.10,>=2.9->tensorflow!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,<3,>=1.15.5->fairness-indicators) (3.2.0)
Requirement already satisfied: zipp>=0.5 in /usr/local/lib/python3.7/dist-packages (from importlib-metadata>=4.4; python_version < "3.10"->markdown>=2.6.8->tensorboard<2.10,>=2.9->tensorflow!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,<3,>=1.15.5->fairness-indicators) (3.8.1)
Requirement already satisfied: jinja2 in /usr/local/lib/python3.7/dist-packages (from notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->witwidget<2,>=1.4.4->fairness-indicators) (2.11.3)
Requirement already satisfied: jupyter-core>=4.4.0 in /usr/local/lib/python3.7/dist-packages (from notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->witwidget<2,>=1.4.4->fairness-indicators) (4.11.1)
Requirement already satisfied: terminado>=0.8.1 in /usr/local/lib/python3.7/dist-packages (from notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->witwidget<2,>=1.4.4->fairness-indicators) (0.13.3)
Requirement already satisfied: nbformat in /usr/local/lib/python3.7/dist-packages (from notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->witwidget<2,>=1.4.4->fairness-indicators) (5.4.0)
Requirement already satisfied: Send2Trash in /usr/local/lib/python3.7/dist-packages (from notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->witwidget<2,>=1.4.4->fairness-indicators) (1.8.0)
Requirement already satisfied: nbconvert in /usr/local/lib/python3.7/dist-packages (from notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->witwidget<2,>=1.4.4->fairness-indicators) (5.6.1)
Requirement already satisfied: pyzmq>=13 in /usr/local/lib/python3.7/dist-packages (from jupyter-client->ipykernel>=4.5.1->ipywidgets>=7.0.0->witwidget<2,>=1.4.4->fairness-indicators) (23.2.1)
Requirement already satisfied: MarkupSafe>=0.23 in /usr/local/lib/python3.7/dist-packages (from jinja2->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->witwidget<2,>=1.4.4->fairness-indicators) (2.0.1)
Requirement already satisfied: fastjsonschema in /usr/local/lib/python3.7/dist-packages (from nbformat->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->witwidget<2,>=1.4.4->fairness-indicators) (2.16.1)
Requirement already satisfied: jsonschema>=2.6 in /usr/local/lib/python3.7/dist-packages (from nbformat->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->witwidget<2,>=1.4.4->fairness-indicators) (4.3.3)
Requirement already satisfied: defusedxml in /usr/local/lib/python3.7/dist-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->witwidget<2,>=1.4.4->fairness-indicators) (0.7.1)
Requirement already satisfied: pandocfilters>=1.4.1 in /usr/local/lib/python3.7/dist-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->witwidget<2,>=1.4.4->fairness-indicators) (1.5.0)
Requirement already satisfied: mistune<2,>=0.8.1 in /usr/local/lib/python3.7/dist-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->witwidget<2,>=1.4.4->fairness-indicators) (0.8.4)
Requirement already satisfied: entrypoints>=0.2.2 in /usr/local/lib/python3.7/dist-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->witwidget<2,>=1.4.4->fairness-indicators) (0.4)
Requirement already satisfied: testpath in /usr/local/lib/python3.7/dist-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->witwidget<2,>=1.4.4->fairness-indicators) (0.6.0)
Requirement already satisfied: bleach in /usr/local/lib/python3.7/dist-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->witwidget<2,>=1.4.4->fairness-indicators) (5.0.1)
Requirement already satisfied: importlib-resources>=1.4.0; python_version < "3.9" in /usr/local/lib/python3.7/dist-packages (from jsonschema>=2.6->nbformat->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->witwidget<2,>=1.4.4->fairness-indicators) (5.9.0)
Requirement already satisfied: attrs>=17.4.0 in /usr/local/lib/python3.7/dist-packages (from jsonschema>=2.6->nbformat->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->witwidget<2,>=1.4.4->fairness-indicators) (22.1.0)
Requirement already satisfied: pyrsistent!=0.17.0,!=0.17.1,!=0.17.2,>=0.14.0 in /usr/local/lib/python3.7/dist-packages (from jsonschema>=2.6->nbformat->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->witwidget<2,>=1.4.4->fairness-indicators) (0.18.1)
Requirement already satisfied: webencodings in /usr/local/lib/python3.7/dist-packages (from bleach->nbconvert->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->witwidget<2,>=1.4.4->fairness-indicators) (0.5.1)
Building wheels for collected packages: pyfarmhash, dill, google-apitools, docopt
Building wheel for pyfarmhash (setup.py) ... done
Created wheel for pyfarmhash: filename=pyfarmhash-0.3.2-cp37-cp37m-linux_x86_64.whl size=68376 sha256=7b4e08afb0d08bf1906c952ef75ece8f78a5965d9c53ff69c43c71f97fd3475b
Stored in directory: /root/.cache/pip/wheels/53/58/7a/3b040f3a2ee31908e3be916e32660db6db53621ce6eba838dc
Building wheel for dill (setup.py) ... done
Created wheel for dill: filename=dill-0.3.1.1-py3-none-any.whl size=78544 sha256=e5abb286f56de3ad6a0fddab37966a7715776251763e1d62519dc8425940cbcc
Stored in directory: /root/.cache/pip/wheels/a4/61/fd/c57e374e580aa78a45ed78d5859b3a44436af17e22ca53284f
Building wheel for google-apitools (setup.py) ... done
Created wheel for google-apitools: filename=google_apitools-0.5.31-py3-none-any.whl size=131039 sha256=94575c072150554b64385204eab48949f4af33136c2f90917c3f5e6d76d5382b
Stored in directory: /root/.cache/pip/wheels/19/b5/2f/1cc3cf2b31e7a9cd1508731212526d9550271274d351c96f16
Building wheel for docopt (setup.py) ... done
Created wheel for docopt: filename=docopt-0.6.2-py2.py3-none-any.whl size=13723 sha256=8524159c41972b02d110a22309520174cb9151f5a54d26d44343b860de6b1761
Stored in directory: /root/.cache/pip/wheels/72/b0/3f/1d95f96ff986c7dfffe46ce2be4062f38ebd04b506c77c81b9
Successfully built pyfarmhash dill google-apitools docopt
Installing collected packages: flatbuffers, gast, keras, tensorboard, tensorflow-estimator, tensorflow, witwidget, proto-plus, docopt, hdfs, fastavro, orjson, dill, pymongo, pyarrow, cloudpickle, grpc-google-iam-v1, grpcio-status, google-cloud-pubsub, grpcio-gcp, google-cloud-bigtable, google-cloud-recommendations-ai, google-cloud-spanner, google-cloud-vision, google-cloud-bigquery-storage, google-cloud-language, fasteners, google-apitools, google-cloud-videointelligence, google-cloud-dlp, overrides, google-cloud-pubsublite, apache-beam, tensorflow-metadata, tensorflow-serving-api, tfx-bsl, tensorflow-model-analysis, joblib, pyfarmhash, tensorflow-data-validation, fairness-indicators, jedi
Attempting uninstall: flatbuffers
Found existing installation: flatbuffers 2.0.7
Uninstalling flatbuffers-2.0.7:
Successfully uninstalled flatbuffers-2.0.7
Attempting uninstall: gast
Found existing installation: gast 0.5.3
Uninstalling gast-0.5.3:
Successfully uninstalled gast-0.5.3
Attempting uninstall: keras
Found existing installation: keras 2.8.0
Uninstalling keras-2.8.0:
Successfully uninstalled keras-2.8.0
Attempting uninstall: tensorboard
Found existing installation: tensorboard 2.8.0
Uninstalling tensorboard-2.8.0:
Successfully uninstalled tensorboard-2.8.0
Attempting uninstall: tensorflow-estimator
Found existing installation: tensorflow-estimator 2.8.0
Uninstalling tensorflow-estimator-2.8.0:
Successfully uninstalled tensorflow-estimator-2.8.0
Attempting uninstall: tensorflow
Found existing installation: tensorflow 2.8.2+zzzcolab20220719082949
Uninstalling tensorflow-2.8.2+zzzcolab20220719082949:
Successfully uninstalled tensorflow-2.8.2+zzzcolab20220719082949
Attempting uninstall: dill
Found existing installation: dill 0.3.5.1
Uninstalling dill-0.3.5.1:
Successfully uninstalled dill-0.3.5.1
Attempting uninstall: pymongo
Found existing installation: pymongo 4.2.0
Uninstalling pymongo-4.2.0:
Successfully uninstalled pymongo-4.2.0
Attempting uninstall: pyarrow
Found existing installation: pyarrow 6.0.1
Uninstalling pyarrow-6.0.1:
Successfully uninstalled pyarrow-6.0.1
Attempting uninstall: cloudpickle
Found existing installation: cloudpickle 1.5.0
Uninstalling cloudpickle-1.5.0:
Successfully uninstalled cloudpickle-1.5.0
Attempting uninstall: google-cloud-bigquery-storage
Found existing installation: google-cloud-bigquery-storage 1.1.2
Uninstalling google-cloud-bigquery-storage-1.1.2:
Successfully uninstalled google-cloud-bigquery-storage-1.1.2
Attempting uninstall: google-cloud-language
Found existing installation: google-cloud-language 1.2.0
Uninstalling google-cloud-language-1.2.0:
Successfully uninstalled google-cloud-language-1.2.0
Attempting uninstall: tensorflow-metadata
Found existing installation: tensorflow-metadata 1.10.0
Uninstalling tensorflow-metadata-1.10.0:
Successfully uninstalled tensorflow-metadata-1.10.0
Attempting uninstall: joblib
Found existing installation: joblib 1.1.0
Uninstalling joblib-1.1.0:
Successfully uninstalled joblib-1.1.0
ERROR: pip's legacy dependency resolver does not consider dependency conflicts when selecting packages. This behaviour is the source of the following dependency conflicts.
google-cloud-bigquery-storage 2.13.2 requires protobuf<4.0.0dev,>=3.19.0, but you'll have protobuf 3.17.3 which is incompatible.
proto-plus 1.22.1 requires protobuf<5.0.0dev,>=3.19.0, but you'll have protobuf 3.17.3 which is incompatible.
grpcio-status 1.48.1 requires grpcio>=1.48.1, but you'll have grpcio 1.47.0 which is incompatible.
google-cloud-pubsub 2.13.6 requires google-api-core[grpc]!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,<3.0.0dev,>=1.32.0, but you'll have google-api-core 1.31.6 which is incompatible.
google-cloud-pubsub 2.13.6 requires protobuf<5.0.0dev,>=3.19.0, but you'll have protobuf 3.17.3 which is incompatible.
google-cloud-bigtable 1.7.2 requires google-cloud-core<3.0dev,>=1.4.1, but you'll have google-cloud-core 1.0.3 which is incompatible.
google-cloud-recommendations-ai 0.7.1 requires google-api-core[grpc]!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,<3.0.0dev,>=1.32.0, but you'll have google-api-core 1.31.6 which is incompatible.
google-cloud-recommendations-ai 0.7.1 requires protobuf<5.0.0dev,>=3.19.0, but you'll have protobuf 3.17.3 which is incompatible.
google-cloud-spanner 1.19.3 requires google-cloud-core<3.0dev,>=1.4.1, but you'll have google-cloud-core 1.0.3 which is incompatible.
google-cloud-dlp 3.8.1 requires google-api-core[grpc]!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,<3.0.0dev,>=1.32.0, but you'll have google-api-core 1.31.6 which is incompatible.
google-cloud-dlp 3.8.1 requires protobuf<5.0.0dev,>=3.19.0, but you'll have protobuf 3.17.3 which is incompatible.
google-cloud-pubsublite 1.4.3 requires google-api-core[grpc]!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,<3.0.0dev,>=1.32.0, but you'll have google-api-core 1.31.6 which is incompatible.
apache-beam 2.41.0 requires requests<3.0.0,>=2.24.0, but you'll have requests 2.23.0 which is incompatible.
Successfully installed apache-beam-2.41.0 cloudpickle-2.1.0 dill-0.3.1.1 docopt-0.6.2 fairness-indicators-0.40.0 fastavro-1.6.0 fasteners-0.17.3 flatbuffers-1.12 gast-0.4.0 google-apitools-0.5.31 google-cloud-bigquery-storage-2.13.2 google-cloud-bigtable-1.7.2 google-cloud-dlp-3.8.1 google-cloud-language-1.3.2 google-cloud-pubsub-2.13.6 google-cloud-pubsublite-1.4.3 google-cloud-recommendations-ai-0.7.1 google-cloud-spanner-1.19.3 google-cloud-videointelligence-1.16.3 google-cloud-vision-1.0.2 grpc-google-iam-v1-0.12.4 grpcio-gcp-0.2.2 grpcio-status-1.48.1 hdfs-2.7.0 jedi-0.18.1 joblib-0.14.1 keras-2.9.0 orjson-3.8.0 overrides-6.2.0 proto-plus-1.22.1 pyarrow-5.0.0 pyfarmhash-0.3.2 pymongo-3.12.3 tensorboard-2.9.1 tensorflow-2.9.2 tensorflow-data-validation-1.9.0 tensorflow-estimator-2.9.0 tensorflow-metadata-1.9.0 tensorflow-model-analysis-0.40.0 tensorflow-serving-api-2.9.1 tfx-bsl-1.9.0 witwidget-1.8.1
Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/
Collecting apache-beam==2.39.0
Downloading apache_beam-2.39.0-cp37-cp37m-manylinux2010_x86_64.whl (10.3 MB)
|████████████████████████████████| 10.3 MB 5.9 MB/s
Requirement already satisfied: protobuf<4,>=3.12.2 in /usr/local/lib/python3.7/dist-packages (from apache-beam==2.39.0) (3.17.3)
Requirement already satisfied: httplib2<0.20.0,>=0.8 in /usr/local/lib/python3.7/dist-packages (from apache-beam==2.39.0) (0.17.4)
Requirement already satisfied: pymongo<4.0.0,>=3.8.0 in /usr/local/lib/python3.7/dist-packages (from apache-beam==2.39.0) (3.12.3)
Requirement already satisfied: python-dateutil<3,>=2.8.0 in /usr/local/lib/python3.7/dist-packages (from apache-beam==2.39.0) (2.8.2)
Requirement already satisfied: pydot<2,>=1.2.0 in /usr/local/lib/python3.7/dist-packages (from apache-beam==2.39.0) (1.3.0)
Requirement already satisfied: dill<0.3.2,>=0.3.1.1 in /usr/local/lib/python3.7/dist-packages (from apache-beam==2.39.0) (0.3.1.1)
Requirement already satisfied: crcmod<2.0,>=1.7 in /usr/local/lib/python3.7/dist-packages (from apache-beam==2.39.0) (1.7)
Requirement already satisfied: hdfs<3.0.0,>=2.1.0 in /usr/local/lib/python3.7/dist-packages (from apache-beam==2.39.0) (2.7.0)
Requirement already satisfied: pyarrow<8.0.0,>=0.15.1 in /usr/local/lib/python3.7/dist-packages (from apache-beam==2.39.0) (5.0.0)
Requirement already satisfied: proto-plus<2,>=1.7.1 in /usr/local/lib/python3.7/dist-packages (from apache-beam==2.39.0) (1.22.1)
Requirement already satisfied: numpy<1.23.0,>=1.14.3 in /usr/local/lib/python3.7/dist-packages (from apache-beam==2.39.0) (1.21.6)
Requirement already satisfied: pytz>=2018.3 in /usr/local/lib/python3.7/dist-packages (from apache-beam==2.39.0) (2022.2.1)
Collecting requests<3.0.0,>=2.24.0
Downloading requests-2.28.1-py3-none-any.whl (62 kB)
|████████████████████████████████| 62 kB 1.7 MB/s
Requirement already satisfied: typing-extensions>=3.7.0 in /usr/local/lib/python3.7/dist-packages (from apache-beam==2.39.0) (4.1.1)
Requirement already satisfied: cloudpickle<3,>=2.0.0 in /usr/local/lib/python3.7/dist-packages (from apache-beam==2.39.0) (2.1.0)
Requirement already satisfied: fastavro<2,>=0.23.6 in /usr/local/lib/python3.7/dist-packages (from apache-beam==2.39.0) (1.6.0)
Requirement already satisfied: orjson<4.0 in /usr/local/lib/python3.7/dist-packages (from apache-beam==2.39.0) (3.8.0)
Requirement already satisfied: grpcio<2,>=1.29.0 in /usr/local/lib/python3.7/dist-packages (from apache-beam==2.39.0) (1.47.0)
Requirement already satisfied: six>=1.5.2 in /usr/local/lib/python3.7/dist-packages (from grpcio<2,>=1.29.0->apache-beam==2.39.0) (1.15.0)
Requirement already satisfied: docopt in /usr/local/lib/python3.7/dist-packages (from hdfs<3.0.0,>=2.1.0->apache-beam==2.39.0) (0.6.2)
Collecting protobuf<4,>=3.12.2
Downloading protobuf-3.20.1-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl (1.0 MB)
|████████████████████████████████| 1.0 MB 48.1 MB/s
Requirement already satisfied: pyparsing>=2.1.4 in /usr/local/lib/python3.7/dist-packages (from pydot<2,>=1.2.0->apache-beam==2.39.0) (3.0.9)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.7/dist-packages (from requests<3.0.0,>=2.24.0->apache-beam==2.39.0) (1.24.3)
Requirement already satisfied: charset-normalizer<3,>=2 in /usr/local/lib/python3.7/dist-packages (from requests<3.0.0,>=2.24.0->apache-beam==2.39.0) (2.1.1)
Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests<3.0.0,>=2.24.0->apache-beam==2.39.0) (2.10)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests<3.0.0,>=2.24.0->apache-beam==2.39.0) (2022.6.15)
Installing collected packages: requests, protobuf, apache-beam
Attempting uninstall: requests
Found existing installation: requests 2.23.0
Uninstalling requests-2.23.0:
Successfully uninstalled requests-2.23.0
Attempting uninstall: protobuf
Found existing installation: protobuf 3.17.3
Uninstalling protobuf-3.17.3:
Successfully uninstalled protobuf-3.17.3
Attempting uninstall: apache-beam
Found existing installation: apache-beam 2.41.0
Uninstalling apache-beam-2.41.0:
Successfully uninstalled apache-beam-2.41.0
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
tensorflow 2.9.2 requires protobuf<3.20,>=3.9.2, but you have protobuf 3.20.1 which is incompatible.
tensorboard 2.9.1 requires protobuf<3.20,>=3.9.2, but you have protobuf 3.20.1 which is incompatible.
grpcio-status 1.48.1 requires grpcio>=1.48.1, but you have grpcio 1.47.0 which is incompatible.
google-cloud-spanner 1.19.3 requires google-cloud-core<3.0dev,>=1.4.1, but you have google-cloud-core 1.0.3 which is incompatible.
google-cloud-recommendations-ai 0.7.1 requires google-api-core[grpc]!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,<3.0.0dev,>=1.32.0, but you have google-api-core 1.31.6 which is incompatible.
google-cloud-pubsublite 1.4.3 requires google-api-core[grpc]!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,<3.0.0dev,>=1.32.0, but you have google-api-core 1.31.6 which is incompatible.
google-cloud-pubsub 2.13.6 requires google-api-core[grpc]!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,<3.0.0dev,>=1.32.0, but you have google-api-core 1.31.6 which is incompatible.
google-cloud-dlp 3.8.1 requires google-api-core[grpc]!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,<3.0.0dev,>=1.32.0, but you have google-api-core 1.31.6 which is incompatible.
google-cloud-bigtable 1.7.2 requires google-cloud-core<3.0dev,>=1.4.1, but you have google-cloud-core 1.0.3 which is incompatible.
Successfully installed apache-beam-2.39.0 protobuf-3.20.1 requests-2.28.1
Note: In Google Colab, you need to restart the runtime at this point to finalize updating the packages you just installed. You can do so by clicking the Restart Runtime
at the end of the output cell above (after installation), or by selecting Runtime > Restart Runtime
in the Menu bar. Please do not proceed to the next section without restarting. You can also ignore the errors about version incompatibility of some of the bundled packages because we won't be using those in this notebook.
Next, you will import the main packages and some utilities you will need in this notebook. Notice that you are not importing fairness-indicators
directly. As mentioned in the intro, this suite of tools is built on top of TFMA so you can just import TFMA to access it.
import tensorflow as tf
import tensorflow_model_analysis as tfma
import tensorflow_datasets as tfds
from tensorflow import keras
The code below should not produce any error. Otherwise, please restart the installation.
print("TensorFlow " + tf.__version__)
print("TFMA " + tfma.VERSION_STRING)
CelebA is a large-scale face attributes dataset with more than 200,000 celebrity images, each with 40 attribute annotations (such as hair type, fashion accessories, facial features, etc.) and 5 landmark locations (eyes, mouth and nose positions). For more details, you can read more in this paper.
With the permission of the owners, this dataset is stored on Google Cloud Storage (GCS) and mostly accessed via TensorFlow Datasets(tfds
). To save on download time and disk space, you will use the GCS bucket specified below as your data directory. This already contains the TFRecords. If you want to download it to your workspace, you can pass a local directory to the data_dir
argument. Just take note that it will take time to complete the download.
# URI of the dataset in Goocle Cloud Storage
GCS_BASE_DIR = "gs://celeb_a_dataset/"
# Load the data using TFDS
data, data_info = tfds.load("celeb_a", data_dir=GCS_BASE_DIR, with_info=True, builder_kwargs={'version':'2.0.0'})
You can preview some of the images in the dataset.
# Take 6 examples and preview images
fig = tfds.show_examples(data['train'].take(6), data_info)
You can also view the dataset as a dataframe to preview the other attributes in tabular format.
# Take 4 examples as a dataframe
df = tfds.as_dataframe(data['train'].take(4), data_info)
# View the dataframe
df.head()
attributes/5_o_Clock_Shadow | attributes/Arched_Eyebrows | attributes/Attractive | attributes/Bags_Under_Eyes | attributes/Bald | attributes/Bangs | attributes/Big_Lips | attributes/Big_Nose | attributes/Black_Hair | attributes/Blond_Hair | ... | landmarks/lefteye_x | landmarks/lefteye_y | landmarks/leftmouth_x | landmarks/leftmouth_y | landmarks/nose_x | landmarks/nose_y | landmarks/righteye_x | landmarks/righteye_y | landmarks/rightmouth_x | landmarks/rightmouth_y | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | False | False | True | False | False | False | True | False | False | False | ... | 68 | 111 | 64 | 149 | 75 | 138 | 109 | 113 | 114 | 153 |
1 | True | True | False | False | True | False | True | True | False | False | ... | 69 | 111 | 68 | 151 | 90 | 133 | 108 | 112 | 109 | 152 |
2 | False | False | True | False | False | True | False | False | False | True | ... | 68 | 112 | 67 | 151 | 84 | 132 | 109 | 111 | 110 | 152 |
3 | False | False | True | False | False | False | False | False | False | False | ... | 69 | 111 | 69 | 153 | 85 | 136 | 107 | 111 | 108 | 152 |
4 rows × 51 columns
Let's list the column header so you can see the attribute names in the dataset. For this notebook, you will just examine the attributes/Young
and attributes/Smiling
features but feel free to pick other features once you've gone over the whole exercise.
# List dataframe header
df.columns
Index(['attributes/5_o_Clock_Shadow', 'attributes/Arched_Eyebrows', 'attributes/Attractive', 'attributes/Bags_Under_Eyes', 'attributes/Bald', 'attributes/Bangs', 'attributes/Big_Lips', 'attributes/Big_Nose', 'attributes/Black_Hair', 'attributes/Blond_Hair', 'attributes/Blurry', 'attributes/Brown_Hair', 'attributes/Bushy_Eyebrows', 'attributes/Chubby', 'attributes/Double_Chin', 'attributes/Eyeglasses', 'attributes/Goatee', 'attributes/Gray_Hair', 'attributes/Heavy_Makeup', 'attributes/High_Cheekbones', 'attributes/Male', 'attributes/Mouth_Slightly_Open', 'attributes/Mustache', 'attributes/Narrow_Eyes', 'attributes/No_Beard', 'attributes/Oval_Face', 'attributes/Pale_Skin', 'attributes/Pointy_Nose', 'attributes/Receding_Hairline', 'attributes/Rosy_Cheeks', 'attributes/Sideburns', 'attributes/Smiling', 'attributes/Straight_Hair', 'attributes/Wavy_Hair', 'attributes/Wearing_Earrings', 'attributes/Wearing_Hat', 'attributes/Wearing_Lipstick', 'attributes/Wearing_Necklace', 'attributes/Wearing_Necktie', 'attributes/Young', 'image', 'landmarks/lefteye_x', 'landmarks/lefteye_y', 'landmarks/leftmouth_x', 'landmarks/leftmouth_y', 'landmarks/nose_x', 'landmarks/nose_y', 'landmarks/righteye_x', 'landmarks/righteye_y', 'landmarks/rightmouth_x', 'landmarks/rightmouth_y'], dtype='object')
In this notebook:
Smiling
attribute*.Young
attribute. You will call this "age group" in this notebook.* While there is little information available about the labeling methodology for this dataset, you will assume that the "Smiling" attribute was determined by a pleased, kind, or amused expression on the subject's face. For the purpose of this example, you will take these labels as ground truth.
Before moving forward, there are several considerations to keep in mind when using CelebA:
Young
attribute (as determined by the dataset labelers) is denoted as either present or absent in the image.Young
attribute is referred to as "age group". A True
will put the image as a member of the Young
age group and a False
will put the image as a member of the Not Young
age group. These are assumptions made as this information is not mentioned in the original paper.Now, you will define the preprocessing functions to prepare your data as model inputs. These include resizing images, normalizing pixels, casting to the right data type, and grouping the features and labels.
# Define Constants
ATTR_KEY = "attributes"
IMAGE_KEY = "image"
LABEL_KEY = "Smiling"
GROUP_KEY = "Young"
IMAGE_SIZE = 28
# Define Preprocessing Function
def preprocess_input_dict(feat_dict):
''' Picks the attributes to study and resizes the images
Args:
feat_dict (dictionary): features from the dataset
Returns:
dictionary containing the resized image, label, and age group
'''
# Separate out the image and target variable from the feature dictionary.
image = feat_dict[IMAGE_KEY]
label = feat_dict[ATTR_KEY][LABEL_KEY]
group = feat_dict[ATTR_KEY][GROUP_KEY]
# Resize and normalize image.
image = tf.cast(image, tf.float32)
image = tf.image.resize(image, [IMAGE_SIZE, IMAGE_SIZE])
image /= 255.0
# Cast label and group to float32.
label = tf.cast(label, tf.float32)
group = tf.cast(group, tf.float32)
# Put the computed values in a dictionary
feat_dict[IMAGE_KEY] = image
feat_dict[ATTR_KEY][LABEL_KEY] = label
feat_dict[ATTR_KEY][GROUP_KEY] = group
return feat_dict
# Define lambda functions to group features and labels for training and evaluation
get_image_and_label = lambda feat_dict: (feat_dict[IMAGE_KEY], feat_dict[ATTR_KEY][LABEL_KEY])
get_image_label_and_group = lambda feat_dict: (feat_dict[IMAGE_KEY], feat_dict[ATTR_KEY][LABEL_KEY], feat_dict[ATTR_KEY][GROUP_KEY])
This next helper function will help split, shuffle, batch and preprocess your training data. For this notebook, you will just develop a model that accepts the image as input and outputs the Smiling
attribute (i.e. label).
def celeb_a_train_data_wo_group(data, batch_size):
'''
Args:
data (TF dataset) - dataset to preprocess
batch_size (int) - batch size
Returns:
Batches of preprocessed datasets containing tuples with (image, label)
'''
celeb_a_train_data = data.shuffle(1024).repeat().batch(batch_size).map(preprocess_input_dict)
return celeb_a_train_data.map(get_image_and_label)
The test
split does not need to be shuffled so you can just preprocess it like below.
# Prepare test data
celeb_a_test_data = data['test'].batch(1).map(preprocess_input_dict).map(get_image_label_and_group)
As a sanity check, you can examine the contents of a one example in the test data. You should see that it is successfully reshaped and the pixels should be normalized.
# Print info about the test data records
for sample in celeb_a_test_data.take(1):
print(f'Data type: {type(sample)}')
print(f'Number of elements: {len(sample)}')
print(f'Shape of 1st element: {sample[0].shape}')
print(f'Shape of 2nd element: {sample[1].shape}')
print(f'Shape of 3rd element: {sample[2].shape}')
print(f'Contents: \n{sample}')
Data type: <class 'tuple'> Number of elements: 3 Shape of 1st element: (1, 28, 28, 3) Shape of 2nd element: (1,) Shape of 3rd element: (1,) Contents: (<tf.Tensor: shape=(1, 28, 28, 3), dtype=float32, numpy= array([[[[0.81317526, 0.7912615 , 0.72465986], [0.85708785, 0.83748 , 0.7542867 ], [0.8946379 , 0.86615646, 0.77189875], ..., [0.527636 , 0.3903811 , 0.16293013], [0.5096639 , 0.3841737 , 0.15280116], [0.5019608 , 0.3882353 , 0.15294118]], [[0.7951531 , 0.75985897, 0.69963485], [0.7954932 , 0.7562775 , 0.7156613 ], [0.80069023, 0.76064926, 0.7249299 ], ..., [0.5149909 , 0.3777361 , 0.1502851 ], [0.50980395, 0.38431373, 0.15294118], [0.5019608 , 0.3882353 , 0.15294118]], [[0.74019605, 0.6931372 , 0.6382353 ], [0.757418 , 0.71035916, 0.6554572 ], [0.7790216 , 0.7319077 , 0.6804222 ], ..., [0.49884957, 0.3802521 , 0.15848838], [0.5060224 , 0.3883753 , 0.13767505], [0.5058824 , 0.38431373, 0.16078432]], ..., [[0.4265211 , 0.3478997 , 0.25378206], [0.37941152, 0.28501377, 0.18291293], [0.5415068 , 0.4387057 , 0.31951806], ..., [0.4872593 , 0.35395598, 0.10908321], [0.5692585 , 0.4866355 , 0.23984672], [0.1599792 , 0.1325282 , 0.06978311]], [[0.322579 , 0.21025406, 0.09330729], [0.2881203 , 0.189941 , 0.07271411], [0.29329234, 0.1928722 , 0.08236799], ..., [0.5442577 , 0.44201183, 0.17365956], [0.152111 , 0.13096255, 0.01717705], [0.3653809 , 0.2843435 , 0.1575379 ]], [[0.26529136, 0.16094968, 0.07551543], [0.27388975, 0.18761528, 0.09587853], [0.22688586, 0.1515357 , 0.0604993 ], ..., [0.2677126 , 0.18372396, 0.03662009], [0.18214768, 0.14041106, 0.0327629 ], [0.5616248 , 0.45547238, 0.18067256]]]], dtype=float32)>, <tf.Tensor: shape=(1,), dtype=float32, numpy=array([1.], dtype=float32)>, <tf.Tensor: shape=(1,), dtype=float32, numpy=array([1.], dtype=float32)>)
With the dataset prepared, you will now assemble a simple tf.keras.Sequential
model to classify your images. The model consists of:
You may be able to greatly improve model performance by adding some complexity (e.g., more densely-connected layers, exploring different activation functions, increasing image size), but that may distract from the goal of demonstrating how easy it is to apply the indicators when working with Keras. For that reason, you will first keep the model simple — but feel free to explore this space later.
def create_model():
'''Builds the simple DNN binary classifier'''
# Build the model using the Sequential API
model = keras.Sequential([
keras.layers.Flatten(input_shape=(IMAGE_SIZE, IMAGE_SIZE, 3), name='image'),
keras.layers.Dense(64, activation='relu'),
keras.layers.Dense(1, activation=None)
])
# Compile the model with hinge loss and binary accuracy metric
model.compile(
optimizer=tf.keras.optimizers.Adam(0.001),
loss='hinge',
metrics='binary_accuracy')
return model
You’re now ready to train your model. To cut back on the amount of execution time and memory, you will train the model by slicing the data into small batches with only a few repeated iterations.
BATCH_SIZE = 32
# Build the model
model = create_model()
# Train the model
model.fit(celeb_a_train_data_wo_group(data['train'], BATCH_SIZE), epochs=5, steps_per_epoch=1000)
Epoch 1/5 1000/1000 [==============================] - 34s 27ms/step - loss: 0.4845 - binary_accuracy: 0.7797 Epoch 2/5 1000/1000 [==============================] - 23s 23ms/step - loss: 0.3673 - binary_accuracy: 0.8356 Epoch 3/5 1000/1000 [==============================] - 23s 23ms/step - loss: 0.3601 - binary_accuracy: 0.8422 Epoch 4/5 1000/1000 [==============================] - 22s 22ms/step - loss: 0.3571 - binary_accuracy: 0.8420 Epoch 5/5 1000/1000 [==============================] - 19s 19ms/step - loss: 0.3368 - binary_accuracy: 0.8501
<keras.callbacks.History at 0x7fe77b8f3990>
Evaluating the model on the test data should result in a final accuracy score of just over 85%. Not bad for a simple model with no fine tuning.
# Evaluate trained model on the test data
results = model.evaluate(celeb_a_test_data)
WARNING:tensorflow:`evaluate()` received a value for `sample_weight`, but `weighted_metrics` were not provided. Did you mean to pass metrics to `weighted_metrics` in `compile()`? If this is intentional you can pass `weighted_metrics=[]` to `compile()` in order to silence this warning.
19962/19962 [==============================] - 58s 3ms/step - loss: 0.2424 - binary_accuracy: 0.8771
You will then save the model so you can analyze it in the next section.
# Define model directory
MODEL_LOCATION = 'saved_model'
# Save the model
model.save(MODEL_LOCATION, save_format='tf')
As you already know, it is usually not enough to just measure your model's performance on global metrics. For instance, performance evaluated across age groups may reveal some shortcomings.
To explore this further, you will evaluate the model with Fairness Indicators via TFMA. In particular, you will see whether there is a significant gap in performance between "Young" and "Not Young" categories when evaluated on false positive rate (FPR).
A false positive error occurs when the model incorrectly predicts the positive class. In this context, a false positive outcome occurs when the ground truth is an image of a celebrity 'Not Smiling' and the model predicts 'Smiling'. While this seems like a relatively mundane error, false positive errors can sometimes cause more problematic behaviors when deployed in a real world application. For instance, a false positive error in a spam classifier could cause a user to miss an important email.
You will mostly follow the same steps as you did in the first ungraded lab of this week. Namely, you will:
EvalConfig
fileEvalSharedModel
Schema
messageYou will need to serialize the preprocessed test dataset so it can be read by TFMA. We've provided a helper function to do just that. Notice that the age group feature is transformed into a string ('Young' or 'Not Young'). This will come in handy in the visualization so the tags are easier to interpret (compared to just 1 or 0).
# Define filename
TFRECORD_FILE = 'celeb_a_test.tfrecord'
def celeb_ds_to_tfrecord(dataset, tfrecord_file):
''' Helper function to convert a TF Dataset to TFRecord
Args:
dataset (TF Dataset) - dataset to save as TFRecord
tfrecord_file (string) - filename to use when writing the TFRecord
'''
# Initialize examples list
examples = []
for row in dataset:
# Get image, label, and group tensors
image = row[0]
label = row[1]
group = row[2]
# Flatten image
image = tf.reshape(image, [-1])
# Instantiate Example
output = tf.train.Example()
# Assign features' numpy arrays to the Example feature values
output.features.feature[IMAGE_KEY].float_list.value.extend(image.numpy().tolist())
output.features.feature[LABEL_KEY].float_list.value.append(label.numpy()[0])
output.features.feature[GROUP_KEY].bytes_list.value.append(b"Young" if group.numpy()[0] else b'Not Young')
# Append to examples list
examples.append(output)
# Serialize examples and save as tfrecord
with tf.io.TFRecordWriter(tfrecord_file) as writer:
for example in examples:
writer.write(example.SerializeToString())
# Use the helper function to serialize the test dataset
celeb_ds_to_tfrecord(celeb_a_test_data, TFRECORD_FILE)
Next, you will define the model, metrics, and slicing specs in an eval config file. As mentioned, you will slice the data across age groups to see if there is an underlying problem. For metrics, you will include the FairnessIndicators
class. These are commonly-identified fairness metrics for binary and multiclass classifiers. Moreover, you will configure a list of thresholds. These will allow you to observe if the model predicts better when the threshold to determine between the two classes is changed (e.g. will the FPR be lower if the model predicts "Smiling" for outputs greater than 0.22?).
# Import helper module
from google.protobuf import text_format
# Write EvalConfig string
eval_config_pbtxt = """
model_specs {
label_key: "%s"
}
metrics_specs {
metrics {
class_name: "FairnessIndicators"
config: '{ "thresholds": [0.22, 0.5, 0.75] }'
}
metrics {
class_name: "ExampleCount"
}
}
slicing_specs {}
slicing_specs { feature_keys: "%s" }
""" % (LABEL_KEY, GROUP_KEY)
# Parse as a Message
eval_config = text_format.Parse(eval_config_pbtxt, tfma.EvalConfig())
This will be identical to the command you ran in an earlier lab. This is needed so TFMA will know how to load and configure your model from disk.
# Create EvalSharedModel
eval_shared_model = tfma.default_eval_shared_model(
eval_saved_model_path=MODEL_LOCATION, eval_config=eval_config)
This is an additional step from your previous TFMA workflow. It is needed particularly because, unlike the TFMA ungraded lab, you didn't include a serving signature with the model. If you remember, the function called by that signature took care of parsing the tfrecords, converting them to the correct data type, and preprocessing. Since that part is not included in this lab, you will need to provide a schema so TFMA will know what data types are in the serialized examples when it parses the tfrecord into a dictionary of features. You will also need to define the dimensions of the image since that is expected by your model input. That is handled by the tensor_representation_group
below.
from tensorflow_metadata.proto.v0 import schema_pb2
from google.protobuf import text_format
# Define Schema message as string
schema_pbtxt = """
tensor_representation_group {
key: ""
value {
tensor_representation {
key: "%s"
value {
dense_tensor {
column_name: "%s"
shape {
dim { size: 28 }
dim { size: 28 }
dim { size: 3 }
}
}
}
}
}
}
feature {
name: "%s"
type: FLOAT
}
feature {
name: "%s"
type: FLOAT
}
feature {
name: "%s"
type: BYTES
}
""" % (IMAGE_KEY, IMAGE_KEY, IMAGE_KEY, LABEL_KEY, GROUP_KEY)
# Parse the schema string to a message
schema = text_format.Parse(schema_pbtxt, schema_pb2.Schema())
You will pass the objects you created in the previous sections to tfma.run_model_analysis()
. As you've done previously, this will take care of loading the model and data, and computing the metrics on the data slices you specified.
# Define output directory
OUTPUT_PATH = 'tfma_output'
# Run model analysis
eval_results = tfma.run_model_analysis(
eval_shared_model=eval_shared_model,
eval_config=eval_config,
data_location=TFRECORD_FILE,
schema=schema,
output_path=OUTPUT_PATH
)
Now you can view the fairness metrics you specified. The FPR should already be selected and you can see that it is considerably higher for the Not Young
age group. Try to explore the widget and see if you can make other findings. Here are some suggestions:
Toggle the threshold drop down and see how the FPR changes with different thresholds
Change the baseline to Young: Young
so the percentage difference (in the table below the chart) will be measured against it.
Deselect the Overall
slice so you can compare the two age groups side by side.
Select other metrics to display and observe their charts.
# Visualize the fairness metrics
tfma.addons.fairness.view.widget_view.render_fairness_indicator(eval_results)
After studying the discrepancies in your predictions, you can then investigate why that happens and have a plan on remidiating it. Aside from changing your model architecture, you can also look first at your training data. fairness-indicators
is also packaged with TFDV so you can use it to generate statistics from your data. Here is a short review on how to do that.
First, you will download the dataset from a GCS bucket into your local workspace. You can use the gsutil tool to help with that.
import tensorflow_data_validation as tfdv
# Define training directory
TRAIN_DIR = f'{GCS_BASE_DIR}celeb_a/2.0.0/celeb_a-train.tfrecord*'
# View tfrecord filenames in GCS
!gsutil ls {TRAIN_DIR}
# Define the data directory
DATA_DIR = 'celeb_a-train-tfrecords'
# Create the data directory
!mkdir {DATA_DIR}
# Download the dataset into the local directory
!gsutil -m cp {TRAIN_DIR} {DATA_DIR}
Now you can generate the statistics for a specific feature.
# Filter features to observe
stats_options = tfdv.StatsOptions(feature_allowlist=['attributes/Young'])
# Compute the statistics for all tf records under the data directory
statistics = tfdv.generate_statistics_from_tfrecord(f'{DATA_DIR}/', stats_options=stats_options)
# Visualize the statistics
tfdv.visualize_statistics(statistics)
The statistics show that the Not Young
age group (i.e. 0
in the attributes/Young
column) has very few images compared to the Young
age group. Maybe that's why the model learns on the Young
images better. You could try adding more Not Young
images and see if your model performs better on this slice.
In this lab, you prepared an image dataset and trained a model to predict one of its attributes (i.e. Smiling
). You then sliced the data based on age groups and computed fairness metrics from the Fairness Indicators
package via TFMA. Though the outcome looks simple, it is an important step in production ML projects because not detecting these problems can greatly affect the experience of your users. Improving these metrics will help you commit to fairness in your applications. We encourage you to try exploring more slices of the dataset and see what findings you can come up with.
For more practice, here is an official tutorial that uses fairness indicators on text data. It uses the What-If-Tool which is another package that comes with Fairness Indicators
. You will also get to explore that in this week's programming assignment.