Coder Social home page Coder Social logo

tensorflow_image_classifier's Introduction

Tensorflow Image Classifier

This is the code for 'Image Classifier in TensorFlow in 5 Min on YouTube. Use this CodeLab by Google as a guide. Also this tutorial is quite helpful.

Requirements

Usage

You just need to make a "classifier" directory with a directory "data" inside it with all your images For example

 [any_path]/my_own_classifier/
 [any_path]/my_own_classifier/data
 [any_path]/my_own_classifier/data/car
 [any_path]/my_own_classifier/data/moto
 [any_path]/my_own_classifier/data/bus

and then put your image on it. This "classifier" directory will have your samples but also trained classifier after execution of "train.sh".

Train process

Just type

 ./train.sh [any_path]/my_own_classifier

And it will do anything for you !

Guess process

Just type for a single guess

 ./guess.sh [any_path]/my_own_classifier /yourfile.jpg

To guess an entire directory

./guessDir.sh [any_path]/classifier [any_path]/srcDir [any_path]/destDir

Example of result

# ./guess.sh /synced/tensor-lib/moto-classifier/ /synced/imagesToTest/moto21.jpg
moto (score = 0.88331)
car (score = 0.11669)

Use an absolute file path for classifier and images because the script dos not support relative path (volume mounting)

The Challenge

Make your own classifier for scientists, then post a clone of this repo with your retrained model in it. (you can name it retrained_graph.pb and it will be around 80 MB. If it's too big for GitHub, upload it to DropBox and post the link to it in your README)

Credits

Credit goes to Xblaster for the majority of this code. I've merely created a wrapper.

tensorflow_image_classifier's People

Contributors

llsourcell avatar metrafonic avatar testbounty 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  avatar  avatar  avatar  avatar  avatar

tensorflow_image_classifier's Issues

: Permission denied /dev/null

i get this when i try to run the ./guess.sh
i have changed file permission on the directory and still no success any idea what this may be?

What is the batch size used by train.sh?

I see there are 4000 steps, but I do not see batch size listed. I have around 6000 images, with 3000 each in 2 categories. I suspect the default settings are not allowing the network to learn all of the provided images.

AttributeError: 'NoneType' object has no attribute 'keys'

SO: Ubuntu 16.04
Docker: 2.5.0
Python3: 3.5.2
Python2 : 2.7.12
Tensorflow: 1.3.0 (intalled at both Python)

Made commands as root

./build.sh
./train.sh /<images/path>/tensorflow_image_classifier-master/pictures/training

Folders structure:

  • tensorflow_image_classifier-master
    • src
    • pictures
      • test
      • training
        • cats
        • dogs

I honestly dont know why im getting this error

root@mw:~<path>/tensorflow_image_classifier-master# ./train.sh /<path>/tensorflow_image_classifier-master/pictures/training
Image directory '/tf_files/data' not found.
Traceback (most recent call last):
  File "tensorflow/examples/image_retraining/retrain.py", line 824, in <module>
    tf.app.run()
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 30, in run
    sys.exit(main(sys.argv))
  File "tensorflow/examples/image_retraining/retrain.py", line 721, in main
    class_count = len(image_lists.keys())
AttributeError: 'NoneType' object has no attribute 'keys'

EDIT: It was without the data folder

Use without docker

Hi,

Although it is very nice how docker bundles everything together it brings with it some obscurity.

It would be nice to have some way to train the net without docker, I don't mind installing stuff manually.

For the guessing part I already found the solution here: #1 (comment)

Things I don't like about docker (in this case):

  • I have to run it as root (sudo)

  • It creates a bunch of sub-volumes on my system partition, I use sub-volumes with another propose and this makes things a little messy.

  • It produces an unnecessary overhead on hard drive usage, I don't want my system partition to be filled up with redundant copies of tf libs and other stuff.

  • I don't know what is going on when I call this scripts, I use pstree -a to see what and how is happening but it's tedious.

Images shoud be .png files

For anyone who faces the same Problem. I tried to use it with png files. But the code expects jpg files. You can convert your files using imagemagick/mogrify. Maybe this should be added to the readme. Saves time for others.

export to tensorflow serving

When I have exported to tensorflow serving, it is deployed and ready to server.
But when we are consuming that service through one python client, it is returning ('Result is: ', outputs {
key: "prediction"
value {
dtype: DT_FLOAT
tensor_shape {
dim {
size: 1
}
dim {
size: 2048
}
}
float_val: 0.317088961601
float_val: 0.0552041605115
float_val: 0.778943479061
float_val: 0.340197831392
float_val: 0.0894310623407
}
I'm not able figure it out, what was the issue. I'm expecting result like /label_image.py.
Could you please guide me on this.
Thanks

Op BatchNormWithGlobalNormalization is deprecated.

After several issues, I managed to get the directory linked with the docker container. I got through all the steps to then realize that something had gone wrong and I would need to start over. I created a new directory with the images to be classified, as well as the label_image.py file that I got from this repository. Opened a new docker container and went through the steps... git pull, and the image_retraining. After it had finished the retraining I ran the label_image.py. This time, it seemed like it was in fact going to run at first... but instead I got the following.

2017-04-22 23:38:17.666525: W tensorflow/core/framework/op_def_util.cc:332] Op BatchNormWithGlobalNormalization is deprecated. It will cease to work in GraphDef version 9. Use tf.nn.batch_normalization().
blue cones (score = 0.09615)

So, my image classifier is looking for different colored cones, and it should be noted that the cone I used was orange, not blue. So it did have a low confidence value on it being blue, which is great. Except I'm not getting values back for the other colors of cones that I'm looking for.

I've tried running this on the images with which I've retrained the tensorflow, blue cones come back with an orange score, orange cones come back with a blue score, and yellow cones come back with a blue score as well.

On top of this, there's that error above where it gives the confidence score on it being a blue cone. I believe this has something to do with inception being outdated, but I wouldn't know how to go about fixing it at this point.

./guess.sh does not output anything into the terminal

ubuntu@ubuntu-VirtualBox:~/tensorflow_image_classifier$ sudo ./guess.sh /home/ubuntu/tensorflow_image_classifier/my_own_classifier /home/ubuntu/tensorflow_image_classifier/prisma/prisma-stpauls.jpg
ubuntu@ubuntu-VirtualBox:~/tensorflow_image_classifier$ 

Error while running guess.sh after training

./guess.sh: 2: cd: can't cd to /tf_files
Traceback (most recent call last):
File "label_image.py", line 1, in
import tensorflow as tf
File "/tensorflow/tensorflow/init.py", line 23, in
from tensorflow.python import *
File "/tensorflow/tensorflow/python/init.py", line 48, in
from tensorflow.python import pywrap_tensorflow
ImportError: cannot import name pywrap_tensorflow

label_image.py Error

Hello, video tutorial for instructions and tried to do, I had the error .. Can you help with this?

I tensorflow/core/common_runtime/gpu/gpu_device.cc:885] Found device 0 with properties:
name: GeForce GTX 1070
major: 6 minor: 1 memoryClockRate (GHz) 1.7715
pciBusID 0000:01:00.0
Total memory: 7.92GiB
Free memory: 7.66GiB
I tensorflow/core/common_runtime/gpu/gpu_device.cc:906] DMA: 0
I tensorflow/core/common_runtime/gpu/gpu_device.cc:916] 0:   Y
I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1070, pci bus id: 0000:01:00.0)
W tensorflow/core/framework/op_def_util.cc:332] Op BatchNormWithGlobalNormalization is deprecated. It will cease to work in GraphDef version 9. Use tf.nn.batch_normalization().
E tensorflow/core/common_runtime/executor.cc:390] Executor failed to create kernel. Invalid argument: NodeDef mentions attr 'dct_method' not in Op<name=DecodeJpeg; signature=contents:string -> image:uint8; attr=channels:int,default=0; attr=ratio:int,default=1; attr=fancy_upscaling:bool,default=true; attr=try_recover_truncated:bool,default=false; attr=acceptable_fraction:float,default=1>; NodeDef: DecodeJpeg = DecodeJpeg[acceptable_fraction=1, channels=3, dct_method="", fancy_upscaling=true, ratio=1, try_recover_truncated=false, _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_DecodeJpeg/contents_0)
	 [[Node: DecodeJpeg = DecodeJpeg[acceptable_fraction=1, channels=3, dct_method="", fancy_upscaling=true, ratio=1, try_recover_truncated=false, _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_DecodeJpeg/contents_0)]]
Traceback (most recent call last):
  File "label_image.py", line 24, in <module>
    {'DecodeJpeg/contents:0': image_data})
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 766, in run
    run_metadata_ptr)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 964, in _run
    feed_dict_string, options, run_metadata)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 1014, in _do_run
    target_list, options, run_metadata)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 1034, in _do_call
    raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: NodeDef mentions attr 'dct_method' not in Op<name=DecodeJpeg; signature=contents:string -> image:uint8; attr=channels:int,default=0; attr=ratio:int,default=1; attr=fancy_upscaling:bool,default=true; attr=try_recover_truncated:bool,default=false; attr=acceptable_fraction:float,default=1>; NodeDef: DecodeJpeg = DecodeJpeg[acceptable_fraction=1, channels=3, dct_method="", fancy_upscaling=true, ratio=1, try_recover_truncated=false, _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_DecodeJpeg/contents_0)
	 [[Node: DecodeJpeg = DecodeJpeg[acceptable_fraction=1, channels=3, dct_method="", fancy_upscaling=true, ratio=1, try_recover_truncated=false, _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_DecodeJpeg/contents_0)]]

Caused by op u'DecodeJpeg', defined at:
  File "label_image.py", line 17, in <module>
    _ = tf.import_graph_def(graph_def, name='')
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/importer.py", line 285, in import_graph_def
    op_def=op_def)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2240, in create_op
    original_op=self._default_original_op, op_def=op_def)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1128, in __init__
    self._traceback = _extract_stack()

InvalidArgumentError (see above for traceback): NodeDef mentions attr 'dct_method' not in Op<name=DecodeJpeg; signature=contents:string -> image:uint8; attr=channels:int,default=0; attr=ratio:int,default=1; attr=fancy_upscaling:bool,default=true; attr=try_recover_truncated:bool,default=false; attr=acceptable_fraction:float,default=1>; NodeDef: DecodeJpeg = DecodeJpeg[acceptable_fraction=1, channels=3, dct_method="", fancy_upscaling=true, ratio=1, try_recover_truncated=false, _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_DecodeJpeg/contents_0)
	 [[Node: DecodeJpeg = DecodeJpeg[acceptable_fraction=1, channels=3, dct_method="", fancy_upscaling=true, ratio=1, try_recover_truncated=false, _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_DecodeJpeg/contents_0)]]

Strange final result

Hi all! I've learned network on different types of clothes, for example scirts, glasses, shoes etc. Then I send picture with model in glasses and hat and scarf (for example). But the result answer looks like this:
hats (score = 0.62886)
scarf (score = 0.33020)
skirts (score = 0.02184)
sweater (score = 0.01306)
glasses (score = 0.00366)
shoes (score = 0.00123)
trousers (score = 0.00115)

But I think it should be like hats and scarf equal score, like 0,6. What should I change for fixing it?

InvalidArgumentError: Invalid JPEG data

I ran train.sh on a number of JPEG images, all of them more or less below 200 KB. Some are larger, and these are typically the ones that throw the error message. Below is the output:

tensorflow.python.framework.errors.InvalidArgumentError: Invalid JPEG data, size 885566
	 [[Node: DecodeJpeg = DecodeJpeg[acceptable_fraction=1, channels=3, fancy_upscaling=true, ratio=1, try_recover_truncated=false, _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_DecodeJpeg/contents_0)]]
Caused by op u'DecodeJpeg', defined at:
  File "tensorflow/examples/image_retraining/retrain.py", line 824, in <module>
    tf.app.run()
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 30, in run
    sys.exit(main(sys.argv))
  File "tensorflow/examples/image_retraining/retrain.py", line 716, in main
    create_inception_graph())
  File "tensorflow/examples/image_retraining/retrain.py", line 300, in create_inception_graph
    RESIZED_INPUT_TENSOR_NAME]))
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/importer.py", line 274, in import_graph_def
    op_def=op_def)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2260, in create_op
    original_op=self._default_original_op, op_def=op_def)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1230, in __init__
    self._traceback = _extract_stack()

Is there an upper limit for the JPEG filesize or pixel count?

docker can't run.

why connect network?

IOError: [Errno url error] invalid proxy for http: 'docker.for.mac.localhost:54321'

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.