Code Monkey home page Code Monkey logo

tensorflow-xception's Introduction

TensorFlow-Xception

TensorFlow implementation of the Xception Model by François Chollet, based on the paper: Xception: Deep Learning with Depthwise Separable Convolutions.

As an example, the model will be trained on the Flowers dataset.

Contents

  1. xception.py: The model implementation file.
  2. xception_preprocessing.py: This is the exact same preprocessing used for inception models.
  3. xception_test.py: A test file to check for the correctness of the model implementation. Can be executed by itself.
  4. write_pb.py: A file to freeze your graph for inference purposes after training your model.
  5. train_flowers.py: An example script to train an Xception model on the flowers dataset.
  6. eval_flowers.py: An example script to evaluate your trained Xception model.
  7. dataset: A folder containing the flowers dataset prepared in TFRecords format.

How to Run

  1. run python train_flowers.py from the root directory to start training your Xception model from scratch on the Flowers dataset. A log directory will be created.
  2. run tensorboard --logdir=log on the root directory to get your tensorboard visualizations.
  3. Tweak around with the hyperparameters and have fun! :D

Customization

You can simply change the dataset files and the appropriate names (i.e. anything that has the name 'flowers') to use the network for your own purposes. Importantly, you should be able to obtain the TFRecord files for your own dataset to start training as the data pipeline is dependent on TFRecord files. To learn more about preparing a dataset with TFRecord files, see this guide for a reference.

References

  1. Xception: Deep Learning with Depthwise Separable Convolutions.
  2. Code from the transfer learning guide
  3. Keras implementation of the model
  4. TF-Slim layers reference

Citation

If you are using this work in your research, please consider citing:

@misc{kwot_sin_lee_2017_3403277,
  author       = {Kwot Sin Lee},
  title        = {kwotsin/TensorFlow-Xception: TensorFlow-Xception},
  month        = may,
  year         = 2017,
  doi          = {10.5281/zenodo.3403277},
  url          = {https://doi.org/10.5281/zenodo.3403277}
}

DOI

tensorflow-xception's People

Contributors

kwotsin avatar mlopezantequera 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

tensorflow-xception's Issues

Is 1024 correct dim for residual layer in xception exit flow?

Hi @kwotsin,

A bunch of thanks for implementing the xception network on tensorflow. I am looking at page-5 of xception paper (xception) and noticed that in your implementation exit flow residual layer have been initialized at 1024 instead of 728 coming from middle flow (ref:

residual = slim.conv2d(net, 1024, [1,1], stride=2, scope='block12_res_conv')
). Is this intentional? Please excuse if I am missing something obvious.

Thanks,
-- d

Did you set two batch_norm layers for a single conv2d layer?

I notice the following code sets a batch_norm_fn for slim.conv2d:

batch_norm_params = {
        'decay': batch_norm_decay,
        'epsilon': batch_norm_epsilon,
    }
    # Set parameters for batch_norm. Note: Do not set activation function as it's preset to None already.
    with slim.arg_scope([slim.conv2d],
                        normalizer_fn=slim.batch_norm,
                        normalizer_params=batch_norm_params) as scope:

However, the batch_norm for conv2d has be setted in following code:

#Block 1
            net = slim.conv2d(inputs, 32, [3,3], stride=2, padding='valid', scope='block1_conv1')
            net = slim.batch_norm(net, scope='block1_bn1')

Is this a intended setting?

Evaluating issue

Hi Kwot! Thanks for the Tensorflow Xception.

I run the 1789 steps of the pythong train_flowers.py on my computer (CPU) and according to the Tensorboard I reached accurrancy=54%. However after I launch python eval_flowers.py I get the folllowing output and the model predicts every eval pitcure as dandelion (I modified the code to print the text label instead of displaying it on the picture) . What am I doing wrong?

python eval_flowers.py 
INFO:tensorflow:Restoring parameters from ./log/model.ckpt-1772
INFO:tensorflow:global_step/sec: 0
INFO:tensorflow:Epoch: 1/1
INFO:tensorflow:Current Streaming Accuracy: 0.0000
INFO:tensorflow:Global Step 1: Streaming Accuracy: 0.0000 (77.42 sec/step)
INFO:tensorflow:Global Step 2: Streaming Accuracy: 0.1389 (23.17 sec/step)
INFO:tensorflow:Global Step 3: Streaming Accuracy: 0.1528 (18.02 sec/step)
INFO:tensorflow:global_step/sec: 0.033286
INFO:tensorflow:Global Step 4: Streaming Accuracy: 0.1667 (16.17 sec/step)
(...)
INFO:tensorflow:Global Step 10: Streaming Accuracy: 0.2469 (15.40 sec/step)
INFO:tensorflow:global_step/sec: 0.0584161
INFO:tensorflow:Global Step 11: Streaming Accuracy: 0.2472 (15.29 sec/step)
(...)
INFO:tensorflow:Global Step 18: Streaming Accuracy: 0.2484 (14.36 sec/step)
INFO:tensorflow:global_step/sec: 0.0666661
INFO:tensorflow:Global Step 19: Streaming Accuracy: 0.2454 (16.38 sec/step)
(...)
INFO:tensorflow:Global Step 26: Streaming Accuracy: 0.2367 (14.29 sec/step)
INFO:tensorflow:global_step/sec: 0.0666666
INFO:tensorflow:Global Step 27: Streaming Accuracy: 0.2372 (14.73 sec/step)
INFO:tensorflow:Global Step 28: Streaming Accuracy: 0.2428 (14.41 sec/step)
INFO:tensorflow:Global Step 29: Streaming Accuracy: 0.2460 (14.71 sec/step)
INFO:tensorflow:Global Step 30: Streaming Accuracy: 0.2462 (14.35 sec/step)
INFO:tensorflow:Final Streaming Accuracy: 0.2444
INFO:tensorflow:Prediction: dandelion 
 Ground Truth: dandelion 
 Probability: 0.30221
INFO:tensorflow:Prediction: dandelion 
 Ground Truth: dandelion 
 Probability: 0.302133
INFO:tensorflow:Prediction: dandelion 
 Ground Truth: dandelion 
 Probability: 0.302201
INFO:tensorflow:Prediction: dandelion 
 Ground Truth: tulips 
 Probability: 0.302064
INFO:tensorflow:Prediction: dandelion 
 Ground Truth: daisy 
 Probability: 0.302107
INFO:tensorflow:Prediction: dandelion 
 Ground Truth: roses 
 Probability: 0.30195
INFO:tensorflow:Prediction: dandelion 
 Ground Truth: roses 
 Probability: 0.302043
INFO:tensorflow:Prediction: dandelion 
 Ground Truth: dandelion 
 Probability: 0.3023
INFO:tensorflow:Prediction: dandelion 
 Ground Truth: tulips 
 Probability: 0.302177
INFO:tensorflow:Prediction: dandelion 
 Ground Truth: daisy 
 Probability: 0.301616
INFO:tensorflow:Model evaluation has completed! Visit TensorBoard for more information regarding your evaluation.

Load weights

It'd be nice to be able to load the weights provided in the keras implementation by @fchollet.

Are you already working on this? Otherwise I can start doing so.

Features extraction

@kwotsin I want to use the Xception model as feature extractor not for classification for my own dataset. According to my understanding to this point, i must have a pretrained model, although tensorflow has a pretrained Xception model over imagenet dataset, i can not use it, because images in my dataset do not have relationships to images in any class of imagenet. So i trained Xception model over my dataset and save model ( .ckpt and .meta files) to have a pretrained model belong to my images. My question is "How to use this saved files ( .ckpt and .meta files) to extract features of my dataset as a matrix it's rows are images and columns are features?

the bn problem

I find you don't add the bn ops while inference,is that don't need add this ops in update_ops?

The xception has exception when running

Hi, @mlopezantequera @kwotsin

Thank you for sharing so nice codes to us.
I have tested successfully with my code with the AlexNet model which implemented by tensorflow, however there is something wrong with your xception model instead of AlexNet.
Here is the exception in line 66 of xception.py:

InvalidArgumentError (see above for traceback): total number of outputs should be within the range of int which is used in the GPU kernel128 vs 128
[[Node: Xception/block2_dws_conv2/separable_conv2d/depthwise = DepthwiseConv2dNative[T=DT_FLOAT, data_format="NHWC", padding="SAME", strides=[1, 1, 1, 1], _device="/job:localhost/replica:0/task:0/cpu:0"](Xception/block2_relu1, Xception/block2_dws_conv2/depthwise_weights/read)]]

Could you give me a hand for this problem?

Thanks
BR!
From Alex, China

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.