Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using a Non-Local Block significantly reduces accuracy. #18

Open
lin0287 opened this issue Jan 10, 2023 · 1 comment
Open

Using a Non-Local Block significantly reduces accuracy. #18

lin0287 opened this issue Jan 10, 2023 · 1 comment

Comments

@lin0287
Copy link

lin0287 commented Jan 10, 2023

Below is my code:

ResNet50NLBase = NonLocalResNet(
      input_shape=(IMAGE_SIZE, IMAGE_SIZE, 3),
      classes=6,
      include_top=False,
      repetitions=[3, 4, 6, 3]
  )
  ResNet50NL = Model(inputs=ResNet50NLBase.inputs, outputs=ResNet50NLBase.layers[-2].output)

  #model.add(RN50)
  model.add(ResNet50NL)
  model.add(GlobalAveragePooling2D())
  model.add(Dense(6, activation='softmax'))

  model.compile(
      loss='categorical_crossentropy',
      optimizer=Adam(),
      metrics=['categorical_accuracy',
               tfa.metrics.CohenKappa(num_classes=6, sparse_labels=False, weightage="quadratic")]
  )

This has significantly reduced accuracy compared to:

RN50 = tf.keras.applications.resnet50.ResNet50(
    input_shape=(IMAGE_SIZE, IMAGE_SIZE, 3),
    weights='imagenet',
    include_top=False,
    pooling='avg'
)
RN50 = Model(inputs=RN50.inputs, outputs=RN50.layers[-2].output)```
Can you explain this?
@andrewrgarcia
Copy link
Contributor

@lin0287 In my fork of this repo (may merge soon), I added a NonLocalBlock layer in non_local_layerstyle.py that can be used to add the NonLocalBlock directly to model.add() (see README). If you tinker with it, this could help clear the current issue as well as issue #17

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

No branches or pull requests

2 participants