Skip to content
This repository has been archived by the owner on Dec 1, 2021. It is now read-only.

tf_upgrade_v2 for network/classification/resnet.py #1069

Merged

Conversation

ytfksw
Copy link
Contributor

@ytfksw ytfksw commented May 29, 2020

What this patch does to fix the issue.

I converted only the blueoil/network/classification/resnet.py with the command line tool tf_upgrade_v2 to run on tensorflow2 because there are a lot of targets in the network folder.

Here's what I did:

install newest tenosrflow (tensorflow-gpu==1.5.2)
Run the upgrade script tf_upgrade_v2
Check the upgrade report for warnings and errors
Run test (make test)

Link to any relevant issues or pull requests.

@ytfksw ytfksw self-assigned this May 29, 2020
@blueoil-butler blueoil-butler bot added the CI: auto-run Run CI automatically label May 29, 2020
@ytfksw
Copy link
Contributor Author

ytfksw commented May 29, 2020

This is the whole convert log:

TensorFlow 2.0 Upgrade Script
-----------------------------
Converted 1 files
Detected 0 issues that require attention
--------------------------------------------------------------------------------
================================================================================
Detailed log follows:

================================================================================
--------------------------------------------------------------------------------
Processing file 'networks/classification/resnet.py'
 outputting to 'networks/classification/resnet.py'
--------------------------------------------------------------------------------

92:25: INFO: Added keywords to args of function 'tf.nn.avg_pool'
92:25: INFO: Renamed keyword argument for tf.nn.avg_pool from value to input
92:25: INFO: Renamed 'tf.nn.avg_pool' to 'tf.nn.avg_pool2d'
98:25: INFO: Added keywords to args of function 'tf.pad'
173:21: INFO: Renamed 'tf.Print' to 'tf.compat.v1.Print'
173:39: INFO: Added keywords to args of function 'tf.shape'
173:57: INFO: Added keywords to args of function 'tf.argmax'
174:22: INFO: Renamed 'tf.Print' to 'tf.compat.v1.Print'
174:41: INFO: Added keywords to args of function 'tf.shape'
174:60: INFO: Added keywords to args of function 'tf.argmax'
176:25: INFO: Added keywords to args of function 'tf.reduce_sum'
181:29: INFO: Added keywords to args of function 'tf.reduce_mean'
--------------------------------------------------------------------------------

@ytfksw
Copy link
Contributor Author

ytfksw commented May 29, 2020

tf_upgrade_v2 sometimes changed argment to keyword argument.
I deleted the keyword argument and checking it one by one (f172aa5), because the arguments become meaninglessly long .

Because API has changed by changing from tf1 to tf2.
It seems to have been converted to a keyword argument to avoid misunderstanding.

avg_pool
tf1:https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/nn/avg_pool

tf.nn.avg_pool(
    value,
    ksize,
    strides,
    padding,
    data_format='NHWC',
    name=None,
    input=None
)

tf2:https://www.tensorflow.org/api_docs/python/tf/nn/avg_pool2d

tf.nn.avg_pool2d(
    input, ksize, strides, padding, data_format='NHWC', name=None
)

tf.pad
tf1:https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/pad

tf.pad(
    tensor,
    paddings,
    mode='CONSTANT',
    name=None,
    constant_values=0
)

tf2:https://www.tensorflow.org/api_docs/python/tf/pad

tf.shape(
    tensor, paddings, mode='CONSTANT', constant_values=0, name=None
)

tf.shape
tf1:https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/shape

tf.shape(
    input,
    name=None,
    out_type=tf.dtypes.int32
)

tf2:https://www.tensorflow.org/api_docs/python/tf/shape

tf.shape(
    input, out_type=tf.dtypes.int32, name=None
)

tf.argmax

tf1:https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/argmax

tf.math.argmax(
    input,
    axis=None,
    name=None,
    dimension=None,
    output_type=tf.dtypes.int64
)

tf2:https://www.tensorflow.org/api_docs/python/tf/math/argmax

tf.math.argmax(
    input, axis=None, output_type=tf.dtypes.int64, name=None
)

tf.reduce_sum
tf1:https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/reduce_sum

tf.math.reduce_sum(
    input_tensor,
    axis=None,
    keepdims=None,
    name=None,
    reduction_indices=None,
    keep_dims=None
)

tf2:https://www.tensorflow.org/api_docs/python/tf/math/reduce_sum

tf.math.reduce_sum(
    input_tensor, axis=None, keepdims=False, name=None
)

tf.reduce_mean
tf1:https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/reduce_mean

tf.math.reduce_mean(
    input_tensor,
    axis=None,
    keepdims=None,
    name=None,
    reduction_indices=None,
    keep_dims=None
)

tf2:https://www.tensorflow.org/api_docs/python/tf/math/reduce_mean

tf.math.reduce_mean(
    input_tensor, axis=None, keepdims=False, name=None
)

@ytfksw ytfksw force-pushed the convert_tf2_network_classification_resnet branch from ff80e01 to e9eb5db Compare May 29, 2020 11:52
@ytfksw ytfksw marked this pull request as ready for review May 29, 2020 12:30
@bo-code-review-bot
Copy link

This PR needs Approvals as follows.

  • Ownership Approval for / from iizukak, tkng, ruimashita
  • Readability Approval for Python from tkng, tsawada, tfujiwar

Please choose reviewers and requet reviews!

Click to see how to approve each reviews

You can approve this PR by triggered comments as follows.

  • Approve all reviews requested to you (readability and ownership) and LGTM review
    Approval, LGTM

  • Approve all ownership reviews
    Ownership Approval or OA

  • Approve all readability reviews
    Readability Approval or RA

  • Approve specified review targets

    • Example of Ownership Reviewer of /: Ownership Approval for / or OA for /
    • Example of Readability Reviewer of Python: Readability Approval for Python or RA for Python
  • Approve LGTM review
    LGTM

See all trigger comments

Please replace [Target] to review target

  • Ownership Approval
    • Ownership Approval for [Target]
    • OA for [Target]
    • Ownership Approval
    • OA
    • Approval
  • Readability Approval
    • Readability Approval for [Target]
    • RA for [Target]
    • [Target] Readability Approval
    • [Target] RA
    • Readability Approval
    • RA
    • Approval
  • LGTM
    • LGTM
    • lgtm

@ytfksw ytfksw requested a review from iizukak May 29, 2020 12:31
Copy link
Member

@iizukak iizukak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OA

@ytfksw ytfksw requested a review from tfujiwar June 3, 2020 07:47
Comment on lines 173 to 180
labels = tf.compat.v1.Print(labels,
[tf.shape(labels), tf.argmax(labels, axis=1)],
message="labels:",
summarize=200)
softmax = tf.compat.v1.Print(softmax,
[tf.shape(softmax), tf.argmax(softmax, axis=1)],
message="softmax:",
summarize=200)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about this? It's more consistent with the other function calls in this file.

labels = tf.compat.v1.Print(
    labels,
    [tf.shape(labels), tf.argmax(labels, axis=1)],
    message="labels:",
    summarize=200
)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. OK. I fixed it for consistency!

@ytfksw ytfksw force-pushed the convert_tf2_network_classification_resnet branch from ad53179 to b0227b4 Compare June 5, 2020 10:41
@ytfksw ytfksw requested a review from tfujiwar June 5, 2020 10:47
Copy link
Contributor

@tfujiwar tfujiwar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RA

@iizukak
Copy link
Member

iizukak commented Jun 9, 2020

/ready

@bo-mergebot
Copy link
Contributor

bo-mergebot bot commented Jun 9, 2020

⏳Merge job is queued...

@bo-mergebot bo-mergebot bot merged commit 57e0d06 into blue-oil:master Jun 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
CI: auto-run Run CI automatically
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants