Skip to content

Conversation

@sayakpaul
Copy link
Member

@sayakpaul sayakpaul commented Jun 3, 2022

This PR adds the OG of the OGs when it comes to computer vision models: ResNet. There are a few rough edges we need to figure out in the cross-loading of weights.

When I ran RUN_SLOW=1 python -m pytest tests/models/resnet/test_modeling_resnet.py, during the integration test, it complained about weight mismatches for all the layers.

So, naturally, when I did a little standalone integration test locally with the TF model the same issue surfaced and the logit assertion failed. FYI, it fails for the PT model too as mentioned earlier. Here's my integration test for TF model:

from PIL import Image
import numpy as np

from src.transformers.models.resnet.modeling_tf_resnet import TFResNetForImageClassification
from transformers import AutoFeatureExtractor


def prepare_img():
    image = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png")
    return image


feature_extractor = AutoFeatureExtractor.from_pretrained(
    "microsoft/resnet-50"
)
model = TFResNetForImageClassification.from_pretrained(
    "microsoft/resnet-50", from_pt=True
)


image = prepare_img()
inputs = feature_extractor(images=image, return_tensors="tf")
outputs = model(**inputs)

expected_shape = [1, 1000]
assert outputs.logits.shape == expected_shape

expected_slice = np.array([-11.1069, -9.7877, -8.3777])

np.testing.assert_allclose(outputs.logits[0, :3].numpy(), expected_slice, atol=1e-4)

@amyeroberts @FrancescoSaverioZuppichini please advise here. After this issue is resolved I will start working on the test cases.

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Jun 3, 2022

The documentation is not available anymore as the PR was closed or merged.

@sayakpaul
Copy link
Member Author

Should have checked before.

Closing in spirit of #17427

@sayakpaul sayakpaul closed this Jun 3, 2022
@sayakpaul sayakpaul deleted the feat/resnet-tf branch June 3, 2022 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants