简体   繁体   中英

How to convert tf.contrib to Tensorflow 2.0

So I'm trying to implement object detection using Tensorflow and a part of my code uses tf.contrib. The problem is tf.contrib is not supported in Tensorflow 2.0.

I've tried using the tf_upgrade_v2 script but I get the following message:

ERROR: Using member tf.contrib.slim in deprecated module tf.contrib. tf.contrib.slim cannot be converted automatically. tf.contrib will not be distributed with TensorFlow 2.0, please consider an alternative in non-contrib TensorFlow, a community-maintained repository such as tensorflow/addons, or fork the required code.

import functools
import tensorflow as tf
from object_detection.core import box_predictor
from object_detection.utils import shape_utils
from object_detection.utils import static_shape

slim = tf.contrib.slim

Since all the projects in tf.contrib were not officially supported by Tensorflow and it had designated owners for maintaining it.
All the contributions and features were meant to merge into core Tensorflow.

From the Tensorflow 2.0 version all the contrib projects had one of three options for its future: move to core ; move to a separate repository ; or delete , most of which have been reviewed with the respective project owners.

This link provides the details and status for all the projects under tf.contrib .

If the library you are using is moved to the core or separate repository, the TensorFlow's automatic code migration from 1.x to 2.x will not work for tf.contrib projects. You need to change your code manually for these parts, which is suggested going forward.

I can see in the table that tf.contrib.slim is moved to tensorflow/models , you can follow this link for the usage in detail.

I had the same problem with slim and I solved it with TensorFlow-Slim . You have to install this library as pip install --upgrade tf_slim and then substitute slim = tf.contrib.slim in your code with import tf_slim as slim .

For other modules stored in tf.contrib , you have to find where they were moved in TF 2.x

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM