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
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
![](http://cdn2.hubspot.net/hubfs/100006/images/tensorpy_logo_4_p.png "TensorPy")
# TensorPy

[![pypi](https://img.shields.io/pypi/v/tensorpy.svg)](https://pypi.python.org/pypi/tensorpy) [![GitHub stars](https://img.shields.io/github/stars/TensorPy/TensorPy.svg "GitHub stars")](https://github.com/TensorPy/TensorPy/stargazers) [![Python version](https://img.shields.io/badge/python-2.7-22AADD.svg "Python version")](https://docs.python.org/2/) [![MIT License](http://img.shields.io/badge/license-MIT-22BBCC.svg "MIT License")](https://github.com/TensorPy/TensorPy/blob/master/LICENSE) [![Join the chat at https://gitter.im/TensorPy/Lobby](https://badges.gitter.im/TensorPy/TensorPy.svg)](https://gitter.im/TensorPy/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![pypi](https://img.shields.io/pypi/v/tensorpy.svg)](https://pypi.python.org/pypi/tensorpy) [![Python version](https://img.shields.io/badge/python-2.7,_3.*-22AADD.svg "Python version")](https://docs.python.org/2/) [![MIT License](http://img.shields.io/badge/license-MIT-22BBCC.svg "MIT License")](https://github.com/TensorPy/TensorPy/blob/master/LICENSE) [![Join the chat at https://gitter.im/TensorPy/Lobby](https://badges.gitter.im/TensorPy/TensorPy.svg)](https://gitter.im/TensorPy/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![GitHub stars](https://img.shields.io/github/stars/TensorPy/TensorPy.svg "GitHub stars")](https://github.com/TensorPy/TensorPy/stargazers)

**Easy Image Classification with TensorFlow**

Expand All @@ -11,7 +11,7 @@

Now runs **much faster** since video released!

You can use TensorPy to classify images by simply passing a URL on the command line, or by using TensorPy in your Python programs. **[TensorFlow](https://www.tensorflow.org/)** does all the image-recognition work. TensorPy also simplifies TensorFlow installation by automating several setup steps into a single script (See **[install.sh](https://github.com/TensorPy/TensorPy/blob/master/install.sh)** for details).
You can use TensorPy to classify images by simply passing a URL on the command line, or by using TensorPy in your Python programs. **[TensorFlow](https://www.tensorflow.org/)** does all the real work. TensorPy also simplifies TensorFlow installation by automating several setup steps into a single script (See **[install.sh](https://github.com/TensorPy/TensorPy/blob/master/install.sh)** and **[python3_install.sh](https://github.com/TensorPy/TensorPy/blob/master/python3_install.sh)** for details).

(Read **[how_tensorpy_works](https://github.com/TensorPy/TensorPy/blob/master/help_docs/how_tensorpy_works.md)** for a detailed explanation of how TensorPy works.)

Expand All @@ -33,12 +33,18 @@ cd TensorPy

#### **Step 3:** Install TensorPy, TensorFlow, and ImageNet/Inception

The **[install.sh](https://github.com/TensorPy/TensorPy/blob/master/install.sh)** script installs everything you need:
For **Python 2.7** users, use **[install.sh](https://github.com/TensorPy/TensorPy/blob/master/install.sh)** to install everything you need.

```bash
./install.sh
```

For **Python 3** users, use **[python3_install.sh](https://github.com/TensorPy/TensorPy/blob/master/python3_install.sh)** to install everything you need.

```bash
./python3_install.sh
```

#### **Step 4:** Run the examples

Classify a single image from a URL:
Expand Down Expand Up @@ -71,6 +77,10 @@ Classify all images from a local folder:
classify examples/images/
```

#### **Examples in Python programs:**

*(**NOTE**: If you're using Python 3 instead of Python 2.7, replace "``python``" with "``python3``" on the command line.)*

Classify an image from a local file path using a Python script: (See **[test_python_file_classify.py](https://github.com/TensorPy/TensorPy/blob/master/examples/test_python_file_classify.py)** for details.)

```bash
Expand Down
2 changes: 1 addition & 1 deletion examples/test_python_folder_classify.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
classifications = image_base.classify_folder_images('./images')
print("*** Displaying Image Classification Results as a list: ***")
for classification in classifications:
print classification
print(classification)
2 changes: 1 addition & 1 deletion examples/test_python_folder_classify_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

dictionary = image_base.classify_folder_images('./images', return_dict=True)
print("*** Displaying Image Classification Results as a dictionary: ***")
print dictionary
print(dictionary)
7 changes: 4 additions & 3 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
# Installs TensorPy, TensorFlow, ImageNet, and required dependancies
# (Made for Python 2.7)

pip install --upgrade pip
echo "Installing TensorPy..."
echo "Installing TensorPy for Python 2.7:"
pip install -r requirements.txt --upgrade
python setup.py install
value="$(uname)"
if [ $value == "Linux" ]
then
echo "Initializing TensorFlow setup on a Linux machine..."
export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.1.0-cp27-none-linux_x86_64.whl
export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.2.1-cp27-none-linux_x86_64.whl
pip install --ignore-installed --upgrade $TF_BINARY_URL
elif [ $value == "Darwin" ]
then
echo "Initializing TensorFlow setup on a MAC..."
export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.1.0-py2-none-any.whl
export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.2.1-py2-none-any.whl
pip install --ignore-installed --upgrade $TF_BINARY_URL
else
echo "Incompatible machine for TensorFlow. Exiting script..."
Expand Down
22 changes: 22 additions & 0 deletions python3_install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Installs TensorPy, TensorFlow, ImageNet, and required dependancies
# (Made for Python 3)

pip3 install --upgrade pip
echo "Installing TensorPy for Python 3:"
pip3 install -r requirements.txt --upgrade
python3 setup.py install
value="$(uname)"
if [ $value == "Linux" ]
then
echo "Initializing TensorFlow setup on a Linux machine..."
pip3 install --upgrade tensorflow
elif [ $value == "Darwin" ]
then
echo "Initializing TensorFlow setup on a MAC..."
pip3 install --upgrade tensorflow
else
echo "Incompatible machine for TensorFlow. Exiting script..."
fi
echo "Downloading ImageNet Inception DB (for classifying images)..."
python3 tensorpy/download_imagenet.py
exit
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
requests==2.18.1
six==1.10.0
Pillow==4.1.1
BeautifulSoup==3.2.1
BeautifulSoup4==4.6.0
-e .
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[bdist_wheel]
# TensorPy works for both Python 2.7 and Python 3
universal=1
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@

setup(
name='tensorpy',
version='1.0.18',
version='1.1.0',
url='http://tensorpy.com',
author='Michael Mintz',
author_email='@mintzworld',
author_email='mdmintz@gmail.com',
maintainer='Michael Mintz',
description='Easy Image Classification with TensorFlow!',
license='The MIT License',
install_requires=[
'requests==2.18.1',
'six==1.10.0',
'Pillow==4.1.1',
'BeautifulSoup==3.2.1',
'BeautifulSoup4==4.6.0',
],
packages=['tensorpy'],
entry_points={
Expand Down
8 changes: 4 additions & 4 deletions tensorpy/classify.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def download_and_classify_image(image_url):
downloads_folder = settings.DOWNLOADS_FOLDER

# Prevent file conflicts by using unique identifiers
hex_name = 'temp_image_%s' % uuid.uuid4().get_hex()
hex_name = 'temp_image_%s' % uuid.uuid4().hex
hex_name_png = hex_name + '.png'
hex_name_jpg = hex_name + '.jpg'

Expand Down Expand Up @@ -65,8 +65,8 @@ def main():
expected_arg = "[A valid PAGE_URL or IMAGE_URL]"
num_args = len(sys.argv)
if num_args < 2 or num_args > 2:
print "\n* INVALID RUN COMMAND! * Usage:"
print "classify %s\n" % 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 Down Expand Up @@ -119,7 +119,7 @@ def main():
"Best match classifications for page images:"
" ***")
images_classified += 1
print best_guess
print(best_guess)
if images_classified >= settings.MAX_IMAGES_PER_PAGE:
break

Expand Down
14 changes: 8 additions & 6 deletions tensorpy/image_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import shutil
import sys
import uuid
from BeautifulSoup import BeautifulSoup
from bs4 import BeautifulSoup
from io import StringIO
from os import listdir
from os.path import isdir, isfile, join
from PIL import Image
from StringIO import StringIO
from tensorpy import classify_image
from tensorpy import settings
from tensorpy import web_core
Expand Down Expand Up @@ -61,10 +61,12 @@ def get_all_images_on_page(page_url):
full_base_url = prefix + "://" + base_url + "/"
html = requests.get(page_url)
completed_source = web_core.rebuild_source(html.text, full_base_url)
soup = BeautifulSoup(completed_source)
imgs = soup.fetch('img', src=True, onload=None)
soup = BeautifulSoup(completed_source, "html.parser")
imgs = soup.find_all("img")
image_url_list = []
for img in imgs:
if not img.has_attr("src") or img.has_attr("onload"):
continue
link = img["src"].split("src=")[-1]
compact_link = link.split('?')[0]
if (compact_link.endswith('.png') or compact_link.endswith('.jpg') or
Expand All @@ -82,7 +84,7 @@ def get_all_images_on_page(page_url):
def classify_image_url(image_url):
""" Classify an image from a URL. """
downloads_folder = settings.DOWNLOADS_FOLDER
hex_name = 'temp_image_%s' % uuid.uuid4().get_hex()
hex_name = 'temp_image_%s' % uuid.uuid4().hex
hex_name_png = hex_name + '.png'
hex_name_jpg = hex_name + '.jpg'
web_core.save_file_as(image_url, hex_name_png)
Expand All @@ -107,7 +109,7 @@ def classify_local_image(file_path):
if not file_path.endswith('.jpg') and not file_path.endswith('.png'):
raise Exception("Expecting a .jpg or .png file!")
downloads_folder = settings.DOWNLOADS_FOLDER
hex_name = 'temp_image_%s' % uuid.uuid4().get_hex()
hex_name = 'temp_image_%s' % uuid.uuid4().hex
hex_name_png = hex_name + '.png'
hex_name_jpg = hex_name + '.jpg'
shutil.copy2(file_path, os.path.join(downloads_folder, hex_name_png))
Expand Down