GithubHelp home page GithubHelp logo

rcmalli / keras-squeezenet Goto Github PK

View Code? Open in Web Editor NEW
405.0 18.0 148.0 10.61 MB

SqueezeNet implementation with Keras Framework

License: MIT License

Python 100.00%
keras squeezenet tensorflow deeplearning

keras-squeezenet's Introduction

Hi there πŸ‘‹

  • πŸ”­ I’m currently working on Computer Vision and Reinforcement Learning.
  • 🎯 I'm experienced in Deep Learning using Pytorch and Tensorflow.

Linkedin Badge Twitter Badge

keras-squeezenet's People

Contributors

davidalmeida23 avatar jeremykawahara avatar rcmalli avatar tariqahassan avatar uetchy 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

keras-squeezenet's Issues

Cant retrain the model with new classification?

I am trying to retrain it with new classes because it doesn't have any proper docs I made many assumptions to retrain it. Basically I am trying to use it for two objects classification so i changed nb_classes to 2 and tried to retrain it. But its giving this error

ValueError: Cannot reshape input of shape (1000,) to shape [1 2 1 1]
Apply node that caused the error: Reshape{4}(conv10_b, TensorConstant{[1 2 1 1]})

This is the full code

#default model and weight of theano
model = get_squeezenet(2, dim_ordering='th')
.
.
y=np.array([[1,0]])
model.fit(im,y, batch_size=1, nb_epoch=1)

```

silently failing on downloading model weights

On keras 2.0, this code hangs,

>>> model = SqueezeNet()
Downloading data from https://github.com/rcmalli/keras-squeezenet/releases/download/v1.0/squeezenet_weights_tf_dim_ordering_tf_kernels.h5

where (for some reason I don't understand) it couldn't make sub directory models. I created it by myself under the current running folder and then it worked.

AttributeError: 'NoneType' object has no attribute 'output' in agegender_train.py when I use import keras-squeezenet

Tensorflow Version

1.14.0

Keras Version

2.3.1

Keras-squeezenet Version

0.4

Bug reports:

I am using the command $ python agegender_train.py gender squeezenet imdb in https://github.com/abars/YoloKerasFaceDetection
So first there was an error in squeezenet.py in keras_squeezenet of

ImportError: cannot import name 'warnings' which I removed by commenting out the warnings section as it was just a print statement. So no more problem with the squeezenet.py but another has occured in the agegender_train.py in line 157

x = base_model.output AttributeError: 'NoneType' object has no attribute 'output'

Eventhough I have keras-squeezenet and the other models in the code example vgg16 or inceptionv3 are running. Only squeezenet is giving this error.

Code Sample:

line 154: from keras_squeezenet import SqueezeNet
line 155: input_tensor = Input(shape=(IMAGE_SIZE, IMAGE_SIZE, 3))
line 156: base_model = SqueezeNet(weights="imagenet", include_top=False, input_tensor=input_tensor)
line 157: x = base_model.output

getting unexpected keyword argument 'include_top'

After using the example I get the following error:

`/keras_squeezenet/squeezenet.py in SqueezeNet(input_tensor, input_shape, weights, classes)
56
57
---> 58 input_shape = _obtain_input_shape(input_shape,default_size=227,min_size=48,data_format=K.image_data_format(),include_top=True)
59 #input_shape = _obtain_input_shape(input_shape,default_size=227,min_size=48,data_format=K.image_data_format())
60

TypeError: _obtain_input_shape() got an unexpected keyword argument 'include_top'`

Any idea what I'm overlooking? thx

Keras version compatibility: Obtain_Input_shape Error

Tensorflow Version v1.11

Please replace this line with Tensorflow version you are using.

Keras Version v2.2.4

Please replace this line with Keras version you are using.

Keras-squeezenet Version v1.1

Please replace this line with Keras-squeezenet version you are using.

Bug reports:

cannot import name '_obtain_input_shape'
Can you suggest a workaround as I don't want to downgrade keras now

Code Sample:

I tried
from keras_applications.imagenet_utils import _obtain_input_shape

but it didn't worked too.

Wrong loss shape when using keras generators

I am facing the following issue when trying to train a Squeezenet with no weights and two classes:

expected loss to have shape (None, 2) but got array with shape (64, 1)

the code has been deeply inspired by this tutorial (https://blog.keras.io/building-powerful-image-classification-models-using-very-little-data.html)

from keras.preprocessing.image import ImageDataGenerator
from keras import backend as K
from keras_squeezenet import SqueezeNet

img_width, img_height = 227, 227

train_data_dir = 'C:/IMAGES/KERAS/train'
validation_data_dir = 'C:/IMAGES/KERAS/validation'
nb_train_samples = 2000
nb_validation_samples = 800
epochs = 2
batch_size = 64

if K.image_data_format() == 'channels_first':
    input_shape = (3, img_width, img_height)
else:
    input_shape = (img_width, img_height, 3)

model = SqueezeNet(weights=None, classes=2)

model.compile(loss='binary_crossentropy',
              optimizer='rmsprop',
              metrics=['accuracy'])

train_datagen = ImageDataGenerator(
    rescale=1. / 255,
    shear_range=0,
    zoom_range=0,
    horizontal_flip=True)

test_datagen = ImageDataGenerator(rescale=1. / 255)

train_generator = train_datagen.flow_from_directory(
    train_data_dir,
    target_size=(img_width, img_height),
    batch_size=batch_size,
    class_mode='binary')

validation_generator = test_datagen.flow_from_directory(
    validation_data_dir,
    target_size=(img_width, img_height),
    batch_size=batch_size,
    class_mode='binary')

model.fit_generator(
    generator=train_generator,
    steps_per_epoch=nb_train_samples // batch_size,
    epochs=epochs,
    validation_data=validation_generator,
    validation_steps=nb_validation_samples // batch_size)

In the folders train and validation there are 2 subfolders (OK and NOK), and both classes are well read by the generators. This is the output from them:

Found 40294 images belonging to 2 classes.
Found 1273 images belonging to 2 classes.

Setting classes=1 when declaring the model solves the error of the expected vs real shape of the loss vector but makes the classifier pointless.

Any idea about how to have more than 1 class when using generators?

SqueezeNet training accuracy stuck at 0.37 for face recognition task

Tensorflow Version

1.6

Keras Version

2.1

Keras-squeezenet Version

Latest

Bug reports:

I am training SqueezeNet on my own face database created from YouTube videos. Apparently the training accuracy is not improving to this magic number of ~0.37. In order to deal with label noise I have tried to include

Are there any known limitations or any help that can be provided would be useful.

Code Sample:

sqnet = SqueezeNet();
sqnet.layers[-1].activation = relu
sqnet.layers[-1].name = 'fc_1'
out = Dense(6, activation='softmax',
name='classifier')(sqnet.layers[-1].output)
sqnet = Model(sqnet.input, out)
for i in range(3,len(sqnet.layers)):
sqnet.layers[-i].trainable = False
sqnet.compile(Adam(),loss='categorical_crossentropy',
metrics=['acc'])
history = sqnet.fit_generator(
trg227,
steps_per_epoch=None,
epochs=2, verbose=1,
validation_data=valg227,
validation_steps=None,
workers=1,
use_multiprocessing=False,
shuffle=True,
initial_epoch=0)

Summary Explanation for squeezenet

Why do I get just one layer for squeezenet.summary()? Since I want to perform grad-cam I need the output of the last conv layer but I am unable to access it. Here is the output for the squeezenet.summary() command:
Layer (type) Output Shape Param #

sequential_7 (Sequential) (None, 1, 1, 1000) 1235496

Total params: 1,235,496
Trainable params: 0
Non-trainable params: 1,235,496

SqueezeNet is slower when using GPU than when using CPU?

I'm trying to measure speed of doing inference on a single image with SqueezeNet. When I run it on CPU, SqueezeNet seems fast enough (comparing to VGG). But when it is on GPU, SqueezeNet gets very slower, even slower than CPU.

Does anyone know why it gets slow on GPU? Should I do something on SqueezeNet when I run it on GPU?

Here are some results of experiments I have made for SqueezeNet vs VGG in terms of their speeds both on CPU and GPU.

On CPU, SqueezeNet is much faster than VGG16.

[inference time]
VGG average response time: 2.21110591888[sec/image]
SqueezeNet average response time: 0.288291954994[sec/image]

On GPU, VGG16 gets really faster, even faster than SqueezeNet. And SqueezeNet gets even slower than it on CPU.

[inference time]
VGG16 average response time: 0.0961683591207[sec/image] # get very fast
SqueezeNet average response time: 1.50337402026[sec/image] # get very slow <= why?

Thanks!

Regression Task

Would it be possible to use keras-squeezenet for a regression task?
I'm thinking about retraining the upper layers with ad images and their click rates and then trying to predict the click rate of new images.
Not sure if this is going to work, but I'd like to try it.

Why need to remove image mean?

In the example code, I found:

# Remove image mean
im[:, :, 0] -= 104.006
im[:, :, 1] -= 116.669
im[:, :, 2] -= 122.679

May I know why we need to remove the mean of image?
Thanks for your time.

Squeezenet Preprocessing

In your "Example Usage" code, you include the following:

x = preprocess_input(x)

Does the original Squeezenet model use preprocessing? Can you point to an example or source for this?

Or, is this something you have chosen to use in this implementation?

keras underscore applications cannot be found from google colabΓΆ

Tensorflow Version

image

Keras Version

image

Keras-squeezenet Version

SqueezeNet v1.1

Bug reports:

While I am using the your squeezenet with my colaboratory environment, i have faced attached error.
I have done all steps that you have mentioned your readme.md
Apprerently the colaboratory or its tf version does not support keras_applications. instead it supports keras.applications I guess.

Code Sample:

image

squeezenet for speech

Can squeezenet be used for speech emotion recognition for feature extraction instead of cnn

how to solve"ImportError: cannot import name 'warnings' from 'keras.layers'"

Tensorflow Version

Please replace this line with Tensorflow version you are using.

Keras Version

Please replace this line with Keras version you are using.

Keras-squeezenet Version

Please replace this line with Keras-squeezenet version you are using.

Bug reports:

why always meet this problem when i am runing sequeezenet.can you give me some advices
Please replace this line with a brief summary of your issue AND if reporting a build issue include the link from:

Code Sample:

Please replace this line with a code sample to replicate the issue.

include_top=False, classes=2: error message

I'm trying to do a binary classification with imagenet weights and set include_top=False and classes = 2, but I receive the following error message:

If using weights as imagenet with include_top as true, classes should be 1000

I think that the condition ( if weights == 'imagenet' and classes != 1000) or the message is wrong. Which one is correct?

Thank you!

Tensorflow Version

Please replace this line with Tensorflow version you are using.

Keras Version

Please replace this line with Keras version you are using.

Keras-squeezenet Version

Please replace this line with Keras-squeezenet version you are using.

Bug reports:

Please replace this line with a brief summary of your issue AND if reporting a build issue include the link from:

Code Sample:

Please replace this line with a code sample to replicate the issue.

Model size?

Here is the code to reproduce result:

import numpy as np
from keras_squeezenet import SqueezeNet
from keras.applications.imagenet_utils import preprocess_input, decode_predictions
from keras.preprocessing import image

model = SqueezeNet()
model.save_weights('model_weights.h5')
model.save('model.h5')

Why model is so big?

du -sh *.h5
4.9M	model.h5
4.9M	model_weights.h5

It's strange, but after running scripts second time I get, what is the reason?

5.9M	model.h5
5.9M	model_weights.h5

In my older Caffe experiments SqeezeNet v1.1 have size 2.9 Mb:
https://github.com/mrgloom/kaggle-dogs-vs-cats-solution

Maxpooling in SqueezeNet

The paper seems to have the Maxpooling layers after Fire 4 and Fire 8 modules, but in your implementation they are present after Fire 3 and Fire 8. Any particular reason why this change in architecture ?

How to train model with new classes

Good day,
Is it possible to train model with new classes, what i am need? For example cat or dog only.
If yes, how we can do it?
Thank you for help :3

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.