Giter Club home page Giter Club logo

keras-nasnet's Introduction

Keras Neural Architecture Search Network (NASNet)

An implementation of "NASNet" models from the paper Learning Transferable Architectures for Scalable Image Recognitio in Keras 2.0+.

Based on the models described in the TFSlim implementation and some modules from the TensorNets implementation

Weights have been ported over from the official NASNet Tensorflow repository.

Since CIFAR weights are not provided, and I don't have the resources to train such large models on CIFAR, those weights will not be provided. External help is appreciated.

Usage

All types of NASNet models can be built. In addition, NASNet Large - NASNet (6 @ 4032) and NASNet Mobile - NASNet (4 @ 1056) are prebuilt and provided as NASNetLarge and NASNetMobile.

Building a speficific NASNet model

from nasnet import NASNet

# the parameters for NASNetLarge
model = NASNet(input_shape=(331, 331, 3),
           penultimate_filters=4032,
           nb_blocks=6,
           stem_filters=96,
           skip_reduction=True,
           use_auxilary_branch=False,
           filters_multiplier=2,
           dropout=0.5,
           classes=1000)

Using Pre-built NASNet models

from nasnet import NASNetLarge, NASNetMobile

model = NASNetLarge(input_shape=(331, 331, 3), dropout=0.5)

Network Overview

keras-nasnet's People

Contributors

titu1994 avatar veronikayu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

keras-nasnet's Issues

Pooling kernel size

Сould you please clarify, It's ok to have pool size less than stride size?
eg nasnet.py line 620
p1 = AveragePooling2D((1, 1), strides=(2, 2), padding='valid', name='adjust_avg_pool_1_%s' % id)(p)

Unable to open object (object 'global_average_pooling2d_1' doesn't exist)

Hi, there. I encountered a problem: KeyError: "Unable to open object (object 'global_average_pooling2d_1' doesn't exist)".
Here my code snippet:

model_name = "nasnet_large_500_300"

net_model = NASNetLarge(input_shape=input_shape, weights='imagenet', include_top=False, pooling='avg')
# append classification layer
x = net_model.output
final_output = Dense(nb_classes, activation='sigmoid', name='fc11')(x)

model = Model(inputs=net_model.input, outputs=final_output)

Could someone help me with this?
UPD: As I found keras couldn't load weights from h5 file

train nasnet model

there is no train script, how can i train this model rather than predict

prediction result varies from time to time

Hi, thank you for fixing nasnet's low accuracy problem. But after I updated the code and weights follow your lead, I found that every time I predict on "elephant.jpg", it got a different score. Here is my prediction code and some results:
input_img = image.load_img('elephant.jpg', target_size=(224,224))
img = image.img_to_array(input_img)
img = np.expand_dims(img, axis=0)
img = preprocess_input(img)
x = tf.keras.applications.nasnet.NASNetMobile(include_top=True,dropout=0, weights='imagenet',
input_tensor=None, input_shape=(224,224,3),
)
preds = x.predict(img)
print('Predicted:', decode_predictions(preds, top=3)[0])

Predicted: [('n02504458', 'African_elephant', 0.6310287), ('n02504013', 'Indian_elephant', 0.16810806), ('n01871265', 'tusker', 0.060016993)]
Predicted: [('n02504458', 'African_elephant', 0.68221015), ('n02504013', 'Indian_elephant', 0.17037697), ('n01871265', 'tusker', 0.057558082)]

I would really appreciate it if you could help me with this problem.

Thanks in advance.

Variable Input Shapes

Would it be possible to extend the functionality beyond just static input sizes? This is useful when we are using this as a backbone to a fully convolutional model. When I create a model with spatial input dimensions as None then the model breaks during inference. because the spatial dimension of two layers being added is off by a factor of 2.

Issue with loading directly download image weights

Due to some network issues, urlretrieve raises error for me when it tries to download model. My solution to that normally is to manually download the .h5 file and put it in the .keras/models file. However, when I did the same here for NASNet the error still persisted. I did some digging and realized that the filed downloaded is named 'NASNet_large_no_top.h5' with capitalizations, but in your nasnet.py you are passing in 'nasnet_large_no_top.h5' with all lower case to keras_utils.getfile(). I fixed the error by renaming the .h5 file accordingly. I know this is a small thing, but it is not immediately obvious and could be frustrating to deal with. Is it possible to change the filename to the appropriate lower case version?

I need your help

Hi, I’m really sorry for this kind of spam but I really need your help.

The reason why I’m forwarding this message is that I’ve been working for a month on a NEW ACTIVATION FUNCTION that according to my experiments works better tan RELU, ELU, LEAKY RELU, SELU, PRELU, SWISH…
Or any other activation function.
I’ve been paying AWS GPUs for the experiments from my own money and working on this as a side project (I’m 17 and still at High School), but now I need your help in order to publish it on the internet for open access to everyone since Arxiv asks me for endorsements. I think the paper is ready for publishing and we could talk about it more extensively if you wished to.

Any help will be much appreciated.
Thanks in advance,
Eric Alcaide.

Value Error: during data augmentation

This is error which i observed during the execution,
ValueError: Error when checking target: expected predictions to have shape (None, 10) but got array with shape (48, 2)

I used this NASNet for my data which is having two classes. Can you guide me to resolve this issue

A bug in your code

I tried to use NASNET you wrote, I find adjust_block function in nasnet.py has a bug:
BatchNormalization should have diff name, but it is not now. I changed these name to adjust_bn_1
and adjust_bn_2_ then pass

Cannot Save Weights with Model Checkpoint

This model as it stands is not useful for custom datasets since there is no easy way to save weights with Model Checkpoint. The layer names are too long. Im hacking my way through trying to figure out a solution but the fact that weights are saveable (at least in Keras 2.1.3) should come with a disclaimer. I realize it is an HD5 issue but still extremely frustrating.

ModelCheckpoint is already set to save weights only and save best only.

Network is not learning :(

Thanks for the amazing work
I am having issue regarding network learning. My NASNet model ain't learning. Training accuracy is improving but validation accuracy isn't changing and stuck at 0.4194.
Training data=600 imgs, testing data=62 imgs
Image shape= (224,224,3)
Epochs=10-15

image

CIFAR10

Have you managed to train NASNet Cifar on the cifar10 dataset? If yes, which results have you obtained? Thanks in advance.

ValueError from NASNet function

edited - thought this was related to include_top, but seems not

e.g.

from nasnet import NASNet
n = NASNet()

gives

ValueError: Operands could not be broadcast together with shapes (331, 331, 168) (331, 331, 96)

I guess this is the same as this, however I'm using tensorflow 1.6

Thanks for the extremely useful work! :)

Got ValueError

I run the code on readme.md

from nasnet import NASNet
model = NASNet(input_shape=(331, 331, 3),
           penultimate_filters=4032,
           nb_blocks=6,
           stem_filters=96,
           skip_reduction=True,
           use_auxilary_branch=False,
           filters_multiplier=2,
           dropout=0.5,
           classes=1000)

And I got.

Traceback (most recent call last): File "<input>", line 12, in <module> File "/home/palm/PycharmProjects/lstm_test/nasnet.py", line 221, in NASNet x, p = _normal_A(x, p, filters, weight_decay, id='%d' % (i)) File "/home/palm/PycharmProjects/lstm_test/nasnet.py", line 665, in _normal_A x3 = add([x3, p], name='normal_add_3_%s' % id) File "/home/palm/miniconda2/lib/python2.7/site-packages/keras/layers/merge.py", line 455, in add return Add(**kwargs)(inputs) File "/home/palm/miniconda2/lib/python2.7/site-packages/keras/engine/topology.py", line 571, in __call__ self.build(input_shapes) File "/home/palm/miniconda2/lib/python2.7/site-packages/keras/layers/merge.py", line 84, in build output_shape = self._compute_elemwise_op_output_shape(output_shape, shape) File "/home/palm/miniconda2/lib/python2.7/site-packages/keras/layers/merge.py", line 55, in _compute_elemwise_op_output_shape str(shape1) + ' ' + str(shape2)) ValueError: Operands could not be broadcast together with shapes (331, 331, 168) (331, 331, 96)

how to load pretrain model?

hello @titu1994 , I am using your code to train my dataset, and i want to train it with a pretrain model that you provide in nasnet.py. But the problem is that my category is 361, and the pre-trained model is 1000, how do I modify it? Looking forward for your reply! : )

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.