Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ One script installs them all. (See [install.sh](https://github.com/mdmintz/Tenso
Classify a single image from a URL:

```bash
python classify.py "https://raw.githubusercontent.com/mdmintz/TensorPy/master/sample_images/happy_animal.jpg"
classify "https://raw.githubusercontent.com/mdmintz/TensorPy/master/sample_images/happy_animal.jpg"
```

Classify all images on a web page:

```bash
python classify.py "https://github.com/mdmintz/TensorPy/tree/master/sample_images"
classify "https://github.com/mdmintz/TensorPy/tree/master/sample_images"
```

Classify a single image from a URL from within a Python program: (See [test_classify.py](https://github.com/mdmintz/TensorPy/blob/master/examples/test_classify.py) for details.)
Classify a single image from a URL from within a Python program: (See [test_python_classify.py](https://github.com/mdmintz/TensorPy/blob/master/examples/test_python_classify.py) for details.)

```bash
cd examples
./run_test_classify.sh
python test_python_classify.py
```
1 change: 0 additions & 1 deletion examples/run_test_classify.sh

This file was deleted.

1 change: 1 addition & 0 deletions examples/test_classify_image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
classify "https://raw.githubusercontent.com/mdmintz/TensorPy/master/sample_images/happy_animal.jpg"
1 change: 1 addition & 0 deletions examples/test_classify_page.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
classify "https://github.com/mdmintz/TensorPy/tree/master/sample_images"
File renamed without changes.
4 changes: 2 additions & 2 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ then
export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.10.0-py2-none-any.whl
pip install $TF_BINARY_URL
else
echo "Incompatible machine for Tensorflow. Exiting script..."
echo "Incompatible machine for TensorFlow. Exiting script..."
fi
echo "Downloading ImageNet (image database for classifying images)..."
python download_imagenet.py
python tensorpy/download_imagenet.py
exit
11 changes: 8 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setup(
name='tensorpy',
version='1.0.3',
version='1.0.4',
url='http://tensorpy.com',
author='Michael Mintz',
author_email='@mintzworld',
Expand All @@ -20,6 +20,11 @@
'six==1.10.0',
'Pillow==3.4.1',
'BeautifulSoup==3.2.1',
],
],
packages=['tensorpy'],
)
entry_points={
'console_scripts': [
'classify = tensorpy.classify:main',
],
},
)
19 changes: 10 additions & 9 deletions classify.py → tensorpy/classify.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
def download_and_classify_image(image_url):
global images_classified
if images_classified >= settings.MAX_IMAGES_PER_PAGE:
return None
return
downloads_folder = settings.DOWNLOADS_FOLDER

# Prevent file conflicts by using unique identifiers
Expand Down Expand Up @@ -59,15 +59,13 @@ def download_and_classify_image(image_url):
downloads_folder + "/temp_image_jpg.jpg")
lock3.release()

return best_guess


if __name__ == "__main__":
expected_arg = "[PAGE(HTML) URL <OR> IMAGE(JPG/PNG) URL]"
def main():
expected_arg = "[PAGE_URL or IMAGE_URL]"
num_args = len(sys.argv)
if num_args < 2 or num_args > 2:
print "Invalid Run Command! Usage:"
print "python classify.py %s" % expected_arg
print "\n* INVALID RUN COMMAND! * Usage:"
print "classify %s\n" % expected_arg
elif num_args == 2:
url = sys.argv[1]
valid_url = web_core.is_valid_url(url)
Expand All @@ -83,13 +81,13 @@ def download_and_classify_image(image_url):
print(best_guess)
print("")
elif content_type == 'html':
global images_classified
image_list = image_base.get_all_images_on_page(url)

if 'linux2' not in sys.platform and settings.MAX_THREADS > 1:
# Multi-threading the work when not using Docker Linux
pool = ThreadPool(settings.MAX_THREADS)
results_list = pool.map(
download_and_classify_image, image_list)
pool.map(download_and_classify_image, image_list)
pool.close()
pool.join()
else:
Expand Down Expand Up @@ -125,3 +123,6 @@ def download_and_classify_image(image_url):
else:
raise Exception(
"Unexpected content type %s. Fix the code!" % content_type)

if __name__ == "__main__":
main()
9 changes: 3 additions & 6 deletions tensorpy/classify_image.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
"""
Simple image classification with Inception.
This is a modified version of the following file:
https://github.com/tensorflow/tensorflow/blob/master
/tensorflow/models/image/imagenet/classify_image.py
"""
""" Simple image classification with Inception. """
# This is a modified version of the following file:
# https://github.com/tensorflow/tensorflow/blob/master/tensorflow/models/image/imagenet/classify_image.py # noqa

from __future__ import absolute_import
from __future__ import division
Expand Down
4 changes: 4 additions & 0 deletions download_imagenet.py → tensorpy/download_imagenet.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
""" Downloading the ImageNet Inception database. """
# This is a modified version of the following file:
# https://github.com/tensorflow/tensorflow/blob/master/tensorflow/models/image/imagenet/classify_image.py # noqa

import os
import sys
import tarfile
Expand Down
1 change: 0 additions & 1 deletion test_classify_image.sh

This file was deleted.

1 change: 0 additions & 1 deletion test_classify_page.sh

This file was deleted.