Import ResNeXt into Keras
Asked Answered
L

1

8

This question could seem difficult but I need to know how tom import ResNeXt model into Keras Tensor-flow, I have tried but there was no use

from keras.applications.resnext import ResNeXt50

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-ca380748170a> in <module>
----> 1 from keras.applications.resnext import ResNeXt50

~/opt/anaconda3/lib/python3.8/site-packages/keras/__init__.py in <module>
  1 from __future__ import absolute_import
  ----> 2 from . import backend
  3 from . import datasets
  4 from . import engine
  5 from . import layers

 ~/opt/anaconda3/lib/python3.8/site-packages/keras/backend/__init__.py in <module>
 65 elif _BACKEND == 'tensorflow':
 66     sys.stderr.write('Using TensorFlow backend.\n')
 ---> 67     from .tensorflow_backend import *
 68 else:
 69     raise ValueError('Unknown backend: ' + str(_BACKEND))

 ~/opt/anaconda3/lib/python3.8/site-packages/keras/backend/tensorflow_backend.py in <module>
 ----> 1 import tensorflow as tf
  2 
  3 from tensorflow.python.training import moving_averages
  4 from tensorflow.python.ops import tensor_array_ops
  5 from tensorflow.python.ops import control_flow_ops

  No module named 'keras.applications.resnext'
Lowenstern answered 17/3, 2021 at 18:36 Comment(0)
B
11

I never understand why some well-used model architectures are not part of the keras application, like SE-Net, ResNeXt. However, there is a well-known keras model zoo repository from where you can get what you need. Classification models Zoo - Keras (and TensorFlow Keras)..

Installing

!pip install git+https://github.com/qubvel/classification_models.git

Importing

# for keras
from classification_models.keras import Classifiers

# for tensorflow keras
from classification_models.tfkeras import Classifiers

Classifiers.models_names()
['resnet18',
 'resnet34',
 'resnet50',
 'resnet101',
 'resnet152',
 'seresnet18',
 'seresnet34',
 'seresnet50',
 'seresnet101',
 'seresnet152',
 'seresnext50',
 'seresnext101',
 'senet154',
 'resnet50v2',
 'resnet101v2',
 'resnet152v2',
 'resnext50',
 'resnext101',
 'vgg16',
 'vgg19',
 'densenet121',
 'densenet169',
 'densenet201',
 'inceptionresnetv2',
 'inceptionv3',
 'xception',
 'nasnetlarge',
 'nasnetmobile',
 'mobilenet',
 'mobilenetv2']

How to use

SeResNeXT, preprocess_input = Classifiers.get('seresnext50')
model = SeResNeXT(include_top = False, input_shape=(224, 224, 3), weights='imagenet')
ResNeXt50, preprocess_input = Classifiers.get('resnext50')
model = ResNeXt50(include_top = False, input_shape=(224, 224, 3), weights='imagenet')
Barbitone answered 18/3, 2021 at 2:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.