Giter Site home page Giter Site logo

stratospark / food-101-keras Goto Github PK

View Code? Open in Web Editor NEW
695.0 695.0 232.0 98.7 MB

Food Classification with Deep Learning in Keras / Tensorflow

Home Page: http://blog.stratospark.com/deep-learning-applied-food-classification-deep-learning-keras.html

License: MIT License

Jupyter Notebook 99.89% Python 0.04% HTML 0.01% CSS 0.01% JavaScript 0.06%
ai deep-learning food-classification image-classification keras machine-learning tensorflow

food-101-keras's People

Contributors

stratospark 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

food-101-keras's Issues

Cut down on requirements.txt

There seems to be a lot of redundant requirements added to the project.
143 dependencies is too large to resolve. Many of them are out-dated and version numbers not updated for others, while some could not be found in pip.

Preferably use '>=' instead of '=='

jupyter notebook stops without any warnings it shows processing but doesn't pull out any results even after several hours

Output:

/anaconda/envs/py35/lib/python3.5/site-packages/ipykernel/__main__.py:19: UserWarning: Update your `Dense` call to the Keras 2 API: `Dense(101, activation="softmax", kernel_initializer="uniform", kernel_regularizer=<keras.reg...)`
/anaconda/envs/py35/lib/python3.5/site-packages/ipykernel/__main__.py:25: UserWarning: Update your `Model` call to the Keras 2 API: `Model(outputs=Tensor("de..., inputs=Tensor("in...)`
/anaconda/envs/py35/lib/python3.5/site-packages/ipykernel/__main__.py:50: UserWarning: The semantics of the Keras 2 argument `steps_per_epoch` is not the same as the Keras 1 argument `samples_per_epoch`. `steps_per_epoch` is the number of batches to draw from the generator at each epoch. Basically steps_per_epoch = samples_per_epoch/batch_size. Similarly `nb_val_samples`->`validation_steps` and `val_samples`->`steps` arguments have changed. Update your method calls accordingly.
/anaconda/envs/py35/lib/python3.5/site-packages/ipykernel/__main__.py:50: UserWarning: Update your `fit_generator` call to the Keras 2 API: `fit_generator(<image_gen..., max_queue_size=10, verbose=1, epochs=32, validation_steps=25250, validation_data=<image_gen..., steps_per_epoch=1183, workers=1, callbacks=[<keras.ca...)`

test train shapes = 25250 75747
Epoch 1/32

INPUT:

%%time
from keras.models import Sequential, Model
from keras.layers import Dense, Dropout, Activation, Flatten
from keras.layers import Convolution2D, MaxPooling2D, ZeroPadding2D, GlobalAveragePooling2D, AveragePooling2D
from keras.layers.normalization import BatchNormalization
from keras.preprocessing.image import ImageDataGenerator
from keras.callbacks import ModelCheckpoint, CSVLogger, LearningRateScheduler, ReduceLROnPlateau
from keras.optimizers import SGD
from keras.regularizers import l2
import keras.backend as K
import math

K.clear_session()

base_model = InceptionV3(weights='imagenet', include_top=False, input_tensor=Input(shape=(299, 299, 3)))
x = base_model.output
x = AveragePooling2D(pool_size=(8, 8))(x)
x = Dropout(.4)(x)
x = Flatten()(x)
predictions = Dense(n_classes, kernel_initializer='uniform', W_regularizer=l2(.0005), activation='softmax')(x)





model = Model(input=base_model.input, output=predictions)

opt = SGD(lr=.01, momentum=.9)
model.compile(optimizer=opt, loss='categorical_crossentropy', metrics=['accuracy'])

checkpointer = ModelCheckpoint(filepath='model4.{epoch:02d}-{val_loss:.2f}.hdf5', verbose=1, save_best_only=True)
csv_logger = CSVLogger('model4.log')

def schedule(epoch):
    if epoch < 15:
        return .01
    elif epoch < 28:
        return .002
    else:
        return .0004
lr_scheduler = LearningRateScheduler(schedule)

print("test train shapes =",X_test.shape[0],X_train.shape[0])

model.fit_generator(train_generator,
                    validation_data=test_generator,
                    nb_val_samples=X_test.shape[0],
                    samples_per_epoch=X_train.shape[0],
                    nb_epoch=32,
                    verbose=1,
                    callbacks=[lr_scheduler, csv_logger, checkpointer],  max_queue_size=10, workers=1)

#fit_generator( callbacks=None use_multiprocessing=False, shuffle=True, initial_epoch=0)

ValueError: high is out of bounds for int32

while running image augmentation, i am getting an error from the module image-gen-extended.py

self.__sync_seed = self.config['seed'] or np.random.randint(low, high=None, size=None)
501

mtrand.pyx in mtrand.RandomState.randint()

ValueError: high is out of bounds for int32

Indian Food Dataset

With the resources you have can you recreate the model such that it works on indian cuisines as well.

Not working in tensorflow 2.1

The model does not get loaded.
Error:-
ValueError: ('Unrecognized keyword arguments:', dict_keys(['input_dtype']))

Improper config format while loading model.

I am getting error (below), while loading model. Can you help? -

from keras.models import load_model
loaded_model = load_model('model4b.10-0.68.hdf5')

ERROR:
deserialize_keras_object
raise ValueError('Improper config format: ' + str(config))
ValueError: Improper config format: {u'l2': 0.0005000000237487257, u'name': u'WeightRegularizer', u'l1': 0.0}

I think you're have done the training using Keras 1 & I'm using Keras 2, do you think this can be the issue?

Ref. - keras-team/keras#6382

Saved model

Hi
Since I currently do not posses any kind of GPU architecture and only posses a laptop, I wanted to ask if you can provide any saved model which i could use to make predictions?:)

lost X_all.hdf5

how to get X_all.hdf5?
without this document the code won't run correctly.

About WISer

Did you reproduce the paper WISer(the highest accuracy reported until now)?

I guess this paper is non-reproducible. There are some issues with the architecture.

In Fig 2, there are 8 filters(3 * 3) with stride 2. Given a 224 * 224 input image, it will shrink to 11 feature maps. But at the bottom, the author adopts an 88 average pooling.
For the slice branch network, the feature maps after 320@ 2455 Conv and 15/3 max pool are high-dimensional.

I send the email to the author. no response.

It's neccesary divide the folders?

Can I create a new branch in this code?,I want to try other models of deep learning and I do not want to separate the folders in train / test, I do not think it is necessary, thank you.

AttributeError: 'numpy.ndarray' object has no attribute 'imread'

I am getting this error

img_arr = img.imread(join(root, subdir, img_name))

Traceback (most recent call last):

  File "<ipython-input-14-391b41e82d54>", line 1, in <module>
    img_arr = img.imread(join(root, subdir, img_name))

AttributeError: 'numpy.ndarray' object has no attribute 'imread'

Pickling error on creating generators

Thank you for making this great tool. Currently I am trying to use your code in my own project.

I have a question regarding multiprocessing. For some reason, train and test generators do not work on Jupyter Notebook:

---------------------------------------------------------------------------
PicklingError                             Traceback (most recent call last)
<ipython-input-25-d9d404f23400> in <module>()
      3 test_datagen.set_pipeline([T.random_transform, T.random_crop, T.preprocess_input])
      4 test_generator = test_datagen.flow(X_test, y_test_cat, batch_size=64, seed=11, pool=pool)
----> 5 for x in test_generator:
      6     print (x)

/home/a161115/dev/food-101-keras/tools/image_gen_extended.pyc in next(self)
    727             index_array, current_index, current_batch_size = next(self.index_generator)
    728         # The transformation of images is not under thread lock so it can be done in parallel
--> 729         result = self.pool.map(process_image_worker, ((self.image_data_generator.process, self.X[j], self.rngs[i%self.batch_size]) for i, j in enumerate(index_array)))
    730         batch_x = np.array(result)
    731 

/usr/lib/python2.7/multiprocessing/pool.pyc in map(self, func, iterable, chunksize)
    249         '''
    250         assert self._state == RUN
--> 251         return self.map_async(func, iterable, chunksize).get()
    252 
    253     def imap(self, func, iterable, chunksize=1):

/usr/lib/python2.7/multiprocessing/pool.pyc in get(self, timeout)
    556             return self._value
    557         else:
--> 558             raise self._value
    559 
    560     def _set(self, i, obj):

PicklingError: Can't pickle <type 'instancemethod'>: attribute lookup __builtin__.instancemethod failed

You noted that the kernel needs to be restarted everytime code is stopped manually. Is there currently a solution for this problem?

CoreML

is it possible to convert this keras model to a CoreML model?

PicklingError: Can't pickle <type 'instancemethod'>: attribute lookup __builtin__.instancemethod failed

Hi.

I am trying to follow your README to train a model and I seem to be getting the following error:

PicklingError: Can't pickle <type 'instancemethod'>: attribute lookup builtin.instancemethod failed

I tried going to keras version 1 but it still doesn't seem to be happy. The problem seems to be with this: model.fit_generator(train_generator,
validation_data=None,
validation_steps=X_test.shape[0],
steps_per_epoch=X_train.shape[0],
epochs=32,
verbose=2,
callbacks=None)
Can you let me know if I'm doing something wrong?

Code is not consistent

The code in food.py and readme is not consistent. Code in food.py has a more deeper layer and has a two step fine tuning.Which one can achieve better performance?

How to get the independent Probability

How to get the independent Probability?
I am trying to detect the food images in composite image using CNN,In the final layer I have done the Softmax classifier to get the prediction,I am getting the result as sum of all probabilities equals to one.But I need to get the independent class probabilities. So can you guide me is there any function that can give the independent class probability.So can you guide me how to get the independent class Probability,Using which function.

Thank you.

Create branch that uses flow_from_directory to avoid preloading all images into RAM

This will hopefully make this project more feasible to run on a wider range of systems. I have extended the multiprocessing ImageDataGenerator to also load and processes images from disk in parallel: https://github.com/stratospark/keras-multiprocess-image-data-generator. It would be interesting to see how long it takes to train the classifier on a a system with less RAM than the total size of the food-101 dataset.

Kernel Restart when loading the data into the variables

Hey I try to rebuild what you did and get an error in the notebook in the following line:
X_test, y_test = load_images('food-101/test', min_side=299)

the kernel restarts ... looks like jupyter notebooks can not handle this amount of data

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.