From e7b26c61101415ae37899423b3e735bf4feb5c03 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Thu, 18 May 2017 02:59:51 -0400 Subject: [PATCH 01/67] Classify local images in a folder --- tensorpy/image_base.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tensorpy/image_base.py b/tensorpy/image_base.py index 2b6905b..e65e1e2 100644 --- a/tensorpy/image_base.py +++ b/tensorpy/image_base.py @@ -1,7 +1,11 @@ import os import requests +import shutil +import sys import uuid from BeautifulSoup import BeautifulSoup +from os import listdir +from os.path import isfile, join from PIL import Image from StringIO import StringIO from tensorpy import classify_image @@ -95,6 +99,41 @@ def get_image_classification(image_url): return best_guess.strip() +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_png = hex_name + '.png' + hex_name_jpg = hex_name + '.jpg' + shutil.copy2(file_path, os.path.join(downloads_folder, hex_name_png)) + convert_image_file_to_jpg( + "%s/%s" % (downloads_folder, hex_name_png)) + os.rename(downloads_folder + "/" + hex_name_png, + downloads_folder + "/temp_image_png.png") + best_guess = classify_image.external_run( + "%s/%s" % (downloads_folder, hex_name_jpg)) + os.rename(downloads_folder + "/" + hex_name_jpg, + downloads_folder + "/temp_image_jpg.jpg") + return best_guess + + +def classify_folder_images(folder_path): + classified_images = [] + files = [f for f in listdir(folder_path) if isfile(join(folder_path, f))] + images = [f for f in files if (f.endswith('.jpg') or f.endswith('.png'))] + total = len(images) + counter = 0 + for image in images: + counter += 1 + sys.stdout.write("\rClassifying Image %d of %s..." % (counter, total)) + sys.stdout.flush() + classified_images.append( + classify_local_image(os.path.join(folder_path, image))) + sys.stdout.write("\rAll classifications have been completed!\n") + return classified_images + + def classify(image_url): """ A shorter method name for get_image_classification() """ return get_image_classification(image_url) From 8057618aeb1b456f56d0ba99f59cb9df0449d95c Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Thu, 18 May 2017 03:00:11 -0400 Subject: [PATCH 02/67] Add more Python examples --- examples/test_python_file_classify.py | 4 ++++ examples/test_python_folder_classify.py | 6 ++++++ 2 files changed, 10 insertions(+) create mode 100644 examples/test_python_file_classify.py create mode 100644 examples/test_python_folder_classify.py diff --git a/examples/test_python_file_classify.py b/examples/test_python_file_classify.py new file mode 100644 index 0000000..8523edf --- /dev/null +++ b/examples/test_python_file_classify.py @@ -0,0 +1,4 @@ +from tensorpy import image_base + +result = image_base.classify_local_image("images/cat_animal.jpg") +print("\nBest match classification:\n%s\n" % result) diff --git a/examples/test_python_folder_classify.py b/examples/test_python_folder_classify.py new file mode 100644 index 0000000..a5e1d66 --- /dev/null +++ b/examples/test_python_folder_classify.py @@ -0,0 +1,6 @@ +from tensorpy import image_base + +classifications = image_base.classify_folder_images('./images') +print("*** Displaying Image Classification Results: ***") +for classification in classifications: + print classification From 367d4db668a1ccadcafe928d7988157e9441711a Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Thu, 18 May 2017 03:02:00 -0400 Subject: [PATCH 03/67] Version 1.0.15 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 9b5ad5b..977b511 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setup( name='tensorpy', - version='1.0.14', + version='1.0.15', url='http://tensorpy.com', author='Michael Mintz', author_email='@mintzworld', From c8514c246a56759a347db22c3c54aff2491e8c89 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Thu, 18 May 2017 03:47:38 -0400 Subject: [PATCH 04/67] Be able to return folder classifications as a Python dict --- tensorpy/image_base.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tensorpy/image_base.py b/tensorpy/image_base.py index e65e1e2..1c39e16 100644 --- a/tensorpy/image_base.py +++ b/tensorpy/image_base.py @@ -118,8 +118,9 @@ def classify_local_image(file_path): return best_guess -def classify_folder_images(folder_path): - classified_images = [] +def classify_folder_images(folder_path, return_dict=False): + classified_images_list = [] + classified_images_dict = {} files = [f for f in listdir(folder_path) if isfile(join(folder_path, f))] images = [f for f in files if (f.endswith('.jpg') or f.endswith('.png'))] total = len(images) @@ -128,10 +129,13 @@ def classify_folder_images(folder_path): counter += 1 sys.stdout.write("\rClassifying Image %d of %s..." % (counter, total)) sys.stdout.flush() - classified_images.append( - classify_local_image(os.path.join(folder_path, image))) + result = classify_local_image(os.path.join(folder_path, image)) + classified_images_list.append(result) + classified_images_dict[image] = result sys.stdout.write("\rAll classifications have been completed!\n") - return classified_images + if return_dict: + return classified_images_dict + return classified_images_list def classify(image_url): From 8d5051965b188131465af87343e66770b888eea2 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Thu, 18 May 2017 03:48:08 -0400 Subject: [PATCH 05/67] Update text --- examples/test_python_folder_classify.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/test_python_folder_classify.py b/examples/test_python_folder_classify.py index a5e1d66..be5ae8a 100644 --- a/examples/test_python_folder_classify.py +++ b/examples/test_python_folder_classify.py @@ -1,6 +1,6 @@ from tensorpy import image_base classifications = image_base.classify_folder_images('./images') -print("*** Displaying Image Classification Results: ***") +print("*** Displaying Image Classification Results as list: ***") for classification in classifications: print classification From a91f7eb2cac8f2cf7042a97f93d0d6aa659bd01c Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Thu, 18 May 2017 03:49:15 -0400 Subject: [PATCH 06/67] Add example to classify folder images into a dictionary --- examples/test_python_folder_classify_dict.py | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 examples/test_python_folder_classify_dict.py diff --git a/examples/test_python_folder_classify_dict.py b/examples/test_python_folder_classify_dict.py new file mode 100644 index 0000000..58683f5 --- /dev/null +++ b/examples/test_python_folder_classify_dict.py @@ -0,0 +1,5 @@ +from tensorpy import image_base + +dictionary = image_base.classify_folder_images('./images', return_dict=True) +print("*** Displaying Image Classification Results as dictionary: ***") +print dictionary From 92a835e5628e23702dd8cb88312d2375d610d91d Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Thu, 18 May 2017 03:50:34 -0400 Subject: [PATCH 07/67] Version 1.0.16 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 977b511..0bcbb42 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setup( name='tensorpy', - version='1.0.15', + version='1.0.16', url='http://tensorpy.com', author='Michael Mintz', author_email='@mintzworld', From 4d227eec32441c1ec249a70e5294ccf5d932fe89 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Thu, 18 May 2017 04:05:22 -0400 Subject: [PATCH 08/67] Update text --- examples/test_python_folder_classify.py | 2 +- examples/test_python_folder_classify_dict.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/test_python_folder_classify.py b/examples/test_python_folder_classify.py index be5ae8a..150f43c 100644 --- a/examples/test_python_folder_classify.py +++ b/examples/test_python_folder_classify.py @@ -1,6 +1,6 @@ from tensorpy import image_base classifications = image_base.classify_folder_images('./images') -print("*** Displaying Image Classification Results as list: ***") +print("*** Displaying Image Classification Results as a list: ***") for classification in classifications: print classification diff --git a/examples/test_python_folder_classify_dict.py b/examples/test_python_folder_classify_dict.py index 58683f5..2f63849 100644 --- a/examples/test_python_folder_classify_dict.py +++ b/examples/test_python_folder_classify_dict.py @@ -1,5 +1,5 @@ from tensorpy import image_base dictionary = image_base.classify_folder_images('./images', return_dict=True) -print("*** Displaying Image Classification Results as dictionary: ***") +print("*** Displaying Image Classification Results as a dictionary: ***") print dictionary From 651f3e688afa17c49a0f42bdec441654c9161074 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Thu, 18 May 2017 21:18:02 -0400 Subject: [PATCH 09/67] Make the "classify" method handle more input types --- tensorpy/image_base.py | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/tensorpy/image_base.py b/tensorpy/image_base.py index 1c39e16..8dbd581 100644 --- a/tensorpy/image_base.py +++ b/tensorpy/image_base.py @@ -5,7 +5,7 @@ import uuid from BeautifulSoup import BeautifulSoup from os import listdir -from os.path import isfile, join +from os.path import isdir, isfile, join from PIL import Image from StringIO import StringIO from tensorpy import classify_image @@ -79,27 +79,31 @@ def get_all_images_on_page(page_url): return image_url_list -def get_image_classification(image_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_png = hex_name + '.png' hex_name_jpg = hex_name + '.jpg' - web_core.save_file_as(image_url, hex_name_png) convert_image_file_to_jpg( "%s/%s" % (downloads_folder, hex_name_png)) os.rename(downloads_folder + "/" + hex_name_png, downloads_folder + "/temp_image_png.png") - best_guess = classify_image.external_run( "%s/%s" % (downloads_folder, hex_name_jpg)) os.rename(downloads_folder + "/" + hex_name_jpg, downloads_folder + "/temp_image_jpg.jpg") - return best_guess.strip() +def get_image_classification(image_url): + # Keep original method name for backwards-compatibility + return classify_image_url(image_url) + + def classify_local_image(file_path): + """ Classify an image from a local 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 @@ -119,6 +123,7 @@ def classify_local_image(file_path): def classify_folder_images(folder_path, return_dict=False): + """ Classify all images from a local folder. """ classified_images_list = [] classified_images_dict = {} files = [f for f in listdir(folder_path) if isfile(join(folder_path, f))] @@ -138,6 +143,16 @@ def classify_folder_images(folder_path, return_dict=False): return classified_images_list -def classify(image_url): - """ A shorter method name for get_image_classification() """ - return get_image_classification(image_url) +def classify(image_url_or_path): + """ Classify an image from a URL or local file path. + If a local folder is provided, all images in the folder + will be classified. """ + is_valid_url = web_core.is_valid_url(image_url_or_path) + if is_valid_url: + return classify_image_url(image_url_or_path) + elif isfile(image_url_or_path): + return classify_local_image(image_url_or_path) + elif isdir(image_url_or_path): + return classify_folder_images(image_url_or_path, return_dict=True) + else: + raise Exception("Expecting an image URL, file path, or folder path!") From d8e9e4dc4cd284efab28380e954fe7b8f96d4241 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Thu, 18 May 2017 21:19:27 -0400 Subject: [PATCH 10/67] Make the "classify" command handle more input types --- tensorpy/classify.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tensorpy/classify.py b/tensorpy/classify.py index 8da263f..5cfa60c 100644 --- a/tensorpy/classify.py +++ b/tensorpy/classify.py @@ -3,6 +3,7 @@ import threading import uuid from multiprocessing.dummy import Pool as ThreadPool +from os.path import isdir, isfile from tensorpy import classify_image from tensorpy import settings from tensorpy import image_base @@ -70,13 +71,24 @@ def main(): url = sys.argv[1] valid_url = web_core.is_valid_url(url) if not valid_url: - raise Exception("Error: %s is not a valid URL!" % url) + file_path = url + if isfile(file_path): + best_guess = image_base.classify_local_image(file_path) + elif isdir(file_path): + best_guess = image_base.classify_folder_images( + file_path, return_dict=True) + else: + raise Exception("Error: %s is not a valid image path!" % url) + print("\n*** Best match classification: ***") + print(best_guess) + print("") + return content_type = web_core.get_content_type(url) if content_type == 'other': raise Exception( "Error: %s does not evaluate to %s" % (url, expected_arg)) elif content_type == 'image': - best_guess = image_base.get_image_classification(url) + best_guess = image_base.classify_image_url(url) print("\n*** Best match classification: ***") print(best_guess) print("") From 3f7819d7dcb9e4bfe703da52c564b1724c474fc3 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Thu, 18 May 2017 21:20:44 -0400 Subject: [PATCH 11/67] Update the ReadMe --- README.md | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2eaa7de..8016465 100644 --- a/README.md +++ b/README.md @@ -56,8 +56,31 @@ classify "https://github.com/TensorPy/TensorPy/tree/master/examples/images" Classify a single image URL from a Python script: (See **[test_python_classify.py](https://github.com/TensorPy/TensorPy/blob/master/examples/test_python_classify.py)** for details.) ```bash -cd examples -python test_python_classify.py +python examples/test_python_classify.py +``` + +Classify an image from a local file path: + +```bash +classify examples/images/cat_animal.jpg +``` + +Classify all images from a local folder: + +```bash +classify examples/images/ +``` + +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 +python examples/test_python_file_classify.py +``` + +Classify all images in a local folder using a Python script: (See **[test_python_folder_classify.py](https://github.com/TensorPy/TensorPy/blob/master/examples/test_python_folder_classify.py)** for details.) + +```bash +python examples/test_python_folder_classify.py ``` ____________ From 30657793f136b5c93f30f427e0a17dccfab08c03 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Thu, 18 May 2017 21:21:02 -0400 Subject: [PATCH 12/67] Version 1.0.17 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 0bcbb42..4dc8aa7 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setup( name='tensorpy', - version='1.0.16', + version='1.0.17', url='http://tensorpy.com', author='Michael Mintz', author_email='@mintzworld', From 090bb53e278f31a07224b9968720ec8ddb35f700 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Thu, 18 May 2017 22:43:57 -0400 Subject: [PATCH 13/67] Update the ReadMe --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8016465..ee247f4 100644 --- a/README.md +++ b/README.md @@ -74,13 +74,15 @@ classify examples/images/ 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 -python examples/test_python_file_classify.py +cd examples +python test_python_file_classify.py ``` Classify all images in a local folder using a Python script: (See **[test_python_folder_classify.py](https://github.com/TensorPy/TensorPy/blob/master/examples/test_python_folder_classify.py)** for details.) ```bash -python examples/test_python_folder_classify.py +cd examples +python test_python_folder_classify.py ``` ____________ From 654f793a0ed15f2a09dec1fcc65cf19543836812 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Thu, 18 May 2017 22:48:57 -0400 Subject: [PATCH 14/67] Update the ReadMe --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ee247f4..5e4517e 100644 --- a/README.md +++ b/README.md @@ -78,13 +78,20 @@ cd examples python test_python_file_classify.py ``` -Classify all images in a local folder using a Python script: (See **[test_python_folder_classify.py](https://github.com/TensorPy/TensorPy/blob/master/examples/test_python_folder_classify.py)** for details.) +Classify all images in a local folder using a Python script (Output = LIST): (See **[test_python_folder_classify.py](https://github.com/TensorPy/TensorPy/blob/master/examples/test_python_folder_classify.py)** for details.) ```bash cd examples python test_python_folder_classify.py ``` +Classify all images in a local folder using a Python script (Output = DICTIONARY): (See **[test_python_folder_classify_dict.py](https://github.com/TensorPy/TensorPy/blob/master/examples/test_python_folder_classify_dict.py)** for details.) + +```bash +cd examples +python test_python_folder_classify_dict.py +``` + ____________ ### Future Work: From 5ca3d8feab480fbabe5f692ff6b5267b93273030 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Sun, 16 Jul 2017 19:21:16 -0400 Subject: [PATCH 15/67] Set hard dependancies to prevent bugs (problem with latest Pillow) --- requirements.txt | 8 ++++---- setup.py | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/requirements.txt b/requirements.txt index fb2f6bf..f2eec66 100755 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ -requests>=2.13.0 -six>=1.10.0 -Pillow>=4.1.1 -BeautifulSoup>=3.2.1 +requests==2.18.1 +six==1.10.0 +Pillow==4.1.1 +BeautifulSoup==3.2.1 -e . diff --git a/setup.py b/setup.py index 4dc8aa7..32d5b43 100644 --- a/setup.py +++ b/setup.py @@ -16,10 +16,10 @@ description='Easy Image Classification with TensorFlow!', license='The MIT License', install_requires=[ - 'requests>=2.13.0', - 'six>=1.10.0', - 'Pillow>=4.1.1', - 'BeautifulSoup>=3.2.1', + 'requests==2.18.1', + 'six==1.10.0', + 'Pillow==4.1.1', + 'BeautifulSoup==3.2.1', ], packages=['tensorpy'], entry_points={ From fb9c20b401de2215ce9de90e726e402067ba914a Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Sun, 16 Jul 2017 19:22:12 -0400 Subject: [PATCH 16/67] Upgrade as needed if dependancies don't match expected version --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 4417369..3b69280 100755 --- a/install.sh +++ b/install.sh @@ -2,7 +2,7 @@ pip install --upgrade pip echo "Installing TensorPy..." -pip install -r requirements.txt +pip install -r requirements.txt --upgrade python setup.py install value="$(uname)" if [ $value == "Linux" ] From 5154dff5aeb03b4213185fa36c20106f585f8418 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Sun, 16 Jul 2017 19:22:50 -0400 Subject: [PATCH 17/67] Version 1.0.18 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 32d5b43..7f301b8 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setup( name='tensorpy', - version='1.0.17', + version='1.0.18', url='http://tensorpy.com', author='Michael Mintz', author_email='@mintzworld', From 5cb2ded033f7f471fa2fead94e66fb44ddc74e3c Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Wed, 19 Jul 2017 03:10:17 -0400 Subject: [PATCH 18/67] Update the Examples ReadMe --- examples/ReadMe.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/ReadMe.md b/examples/ReadMe.md index 541b5c0..17f2efa 100755 --- a/examples/ReadMe.md +++ b/examples/ReadMe.md @@ -1,6 +1,6 @@ ## Running TensorPy Examples -(NOTE: If you didn't install TensorFlow and TensorPy properly from the README instructions, these scripts won't work.) +(NOTE: If you didn't install TensorFlow and TensorPy properly from the [README](https://github.com/TensorPy/TensorPy/blob/master/README.md) instructions, these scripts won't work.) ```bash ./test_classify_image.sh @@ -14,4 +14,6 @@ You can also perform classifications from Python scripts: python test_python_classify.py ``` -(NOTE: If you see any ``*.pyc`` files appear as you run tests, that is compiled bytecode, which is a natural result of running Python code.) +(NOTE: If you see any ``*.pyc`` files appear as you run Python scripts, that is compiled bytecode, which is a natural result of running Python code.) + +For more examples, see Step 4 of the [README](https://github.com/TensorPy/TensorPy/blob/master/README.md). From 60dbc3d7b5b55e7dac045217b6562628f9a3d9e7 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Fri, 21 Jul 2017 13:07:15 -0400 Subject: [PATCH 19/67] Upgrade to the latest version of BeautifulSoup --- requirements.txt | 2 +- setup.py | 2 +- tensorpy/image_base.py | 10 ++++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/requirements.txt b/requirements.txt index f2eec66..e5f2f52 100755 --- a/requirements.txt +++ b/requirements.txt @@ -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 . diff --git a/setup.py b/setup.py index 7f301b8..3239107 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ 'requests==2.18.1', 'six==1.10.0', 'Pillow==4.1.1', - 'BeautifulSoup==3.2.1', + 'BeautifulSoup4==4.6.0', ], packages=['tensorpy'], entry_points={ diff --git a/tensorpy/image_base.py b/tensorpy/image_base.py index 8dbd581..da005ea 100644 --- a/tensorpy/image_base.py +++ b/tensorpy/image_base.py @@ -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 @@ -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 From e034305df489d15789f051c7d44d5e748507c66b Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Fri, 21 Jul 2017 13:13:30 -0400 Subject: [PATCH 20/67] Use uuid4 hex instead of get_hex() for Python 3 compatibility --- tensorpy/image_base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tensorpy/image_base.py b/tensorpy/image_base.py index da005ea..237b6bc 100644 --- a/tensorpy/image_base.py +++ b/tensorpy/image_base.py @@ -84,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) @@ -109,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)) From 4189e54d1f8c17d0a61a4d5a90cd29a3e1c63e9e Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Fri, 21 Jul 2017 13:14:45 -0400 Subject: [PATCH 21/67] Update the TensorPy Python 2.7 install script --- install.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/install.sh b/install.sh index 3b69280..6fd187b 100755 --- a/install.sh +++ b/install.sh @@ -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..." From 7d27b79dda368c3f6d6e0a0f0cdc2e28e028c525 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Fri, 21 Jul 2017 13:15:34 -0400 Subject: [PATCH 22/67] Adding the TensorPy Python 3 install script --- python3_install.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 python3_install.sh diff --git a/python3_install.sh b/python3_install.sh new file mode 100755 index 0000000..5cd5f40 --- /dev/null +++ b/python3_install.sh @@ -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 From 9d5b7e458f500358ba5b18954bb06e9b53e75bcb Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Fri, 21 Jul 2017 13:16:54 -0400 Subject: [PATCH 23/67] Updating uuid4 usage for Python 3 compatibility --- tensorpy/classify.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorpy/classify.py b/tensorpy/classify.py index 5cfa60c..6a8a03a 100644 --- a/tensorpy/classify.py +++ b/tensorpy/classify.py @@ -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' From a622c8924dcd666f243862d47a48a7f3668ee5b1 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Fri, 21 Jul 2017 13:23:03 -0400 Subject: [PATCH 24/67] Python 3 wants print statements to be method calls --- examples/test_python_folder_classify.py | 2 +- examples/test_python_folder_classify_dict.py | 2 +- tensorpy/classify.py | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/test_python_folder_classify.py b/examples/test_python_folder_classify.py index 150f43c..c3c6dc2 100644 --- a/examples/test_python_folder_classify.py +++ b/examples/test_python_folder_classify.py @@ -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) diff --git a/examples/test_python_folder_classify_dict.py b/examples/test_python_folder_classify_dict.py index 2f63849..5119129 100644 --- a/examples/test_python_folder_classify_dict.py +++ b/examples/test_python_folder_classify_dict.py @@ -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) diff --git a/tensorpy/classify.py b/tensorpy/classify.py index 6a8a03a..39ff08e 100644 --- a/tensorpy/classify.py +++ b/tensorpy/classify.py @@ -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) @@ -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 From 55c81e650f9139813b36fda376633baa2dacfa0c Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Fri, 21 Jul 2017 13:23:48 -0400 Subject: [PATCH 25/67] The Python Package Index expects a valid email address --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 3239107..d61d6b8 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ version='1.0.18', 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', From 184948be7ab323ccac6df01cfcd29b43ee8329b7 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Fri, 21 Jul 2017 13:24:12 -0400 Subject: [PATCH 26/67] Update the ReadMe --- README.md | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5e4517e..62d089b 100644 --- a/README.md +++ b/README.md @@ -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** @@ -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.) @@ -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: @@ -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 From 292163bcc5f2909cb09b0f6d8a34262144063657 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Fri, 21 Jul 2017 13:25:31 -0400 Subject: [PATCH 27/67] Version 1.1.0 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index d61d6b8..5f767cf 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setup( name='tensorpy', - version='1.0.18', + version='1.1.0', url='http://tensorpy.com', author='Michael Mintz', author_email='mdmintz@gmail.com', From b4f64c807b7a2d90e72922d1a6e927d46e0507ac Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Fri, 21 Jul 2017 13:43:53 -0400 Subject: [PATCH 28/67] Add a setup.cfg configuration file --- setup.cfg | 3 +++ 1 file changed, 3 insertions(+) create mode 100755 setup.cfg diff --git a/setup.cfg b/setup.cfg new file mode 100755 index 0000000..cb069cd --- /dev/null +++ b/setup.cfg @@ -0,0 +1,3 @@ +[bdist_wheel] +# TensorPy works for both Python 2.7 and Python 3 +universal=1 From 970627fada7518c67a6fcc46a4a191eb1887ba71 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Sun, 30 Jul 2017 15:45:51 -0400 Subject: [PATCH 29/67] Simplify TensorPy Python 3 installation script --- python3_install.sh | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/python3_install.sh b/python3_install.sh index 5cd5f40..4749bf2 100755 --- a/python3_install.sh +++ b/python3_install.sh @@ -5,18 +5,8 @@ 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 "Installing TensorFlow..." +pip3 install --upgrade tensorflow echo "Downloading ImageNet Inception DB (for classifying images)..." python3 tensorpy/download_imagenet.py exit From b0adcddfd559ab22d16deaca429be71f60bb383b Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Thu, 3 Aug 2017 15:47:23 -0400 Subject: [PATCH 30/67] Update ReadMe files --- README.md | 4 +++- help_docs/how_tensorpy_works.md | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 62d089b..4292d20 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ (**[Watch the 2-minute tutorial on YouTube](https://www.youtube.com/watch?v=lVtzaHcUE7Q)**) -Now runs **much faster** since video released! +(**Upgraded** since that video was 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 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). @@ -47,6 +47,8 @@ For **Python 3** users, use **[python3_install.sh](https://github.com/TensorPy/T #### **Step 4:** Run the examples +(NOTE: Run times may vary depending on your Internet connection and computer's CPU speed.) + Classify a single image from a URL: ```bash diff --git a/help_docs/how_tensorpy_works.md b/help_docs/how_tensorpy_works.md index b01300e..0d76f96 100755 --- a/help_docs/how_tensorpy_works.md +++ b/help_docs/how_tensorpy_works.md @@ -1,5 +1,7 @@ ### How TensorPy Works (Detailed Explanation) +(NOTE: Run times may vary depending on your Internet connection and computer's CPU speed.) + Once TensorPy is installed with **[install.sh](https://github.com/TensorPy/TensorPy/blob/master/install.sh)**, a command called ``classify`` is added to your command line, which takes a URL as input. When called, TensorPy determines if that URL links to an image or a web image. If it's an image, TensorPy downloads the image to a new folder called ``downloads_folder``. From there, the image is converted to a JPEG. Then, the image is fed to the local **[tensorpy/classify_image.py](https://github.com/TensorPy/TensorPy/blob/master/tensorpy/classify_image.py)** which tells TensorFlow to use the ImageNet Inception database to classify the image and print out the result. If the ``classify`` command is called with a web page as input, then all images on that page (up to the limit defined in **[tensorpy/settings.py](https://github.com/TensorPy/TensorPy/blob/master/tensorpy/settings.py)**) will get downloaded to ``downloads_folder``, where TensorPy does the work listed above per image, with the exception of images smaller than the minimum size defined in tensorpy/settings.py (currently 50x50 pixels). Images that are too small will be skipped because results have shown that icons and other tiny images get extremely poor classification results. From c2a07e717b3532413a153ef6cf805fd29df18d62 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Mon, 1 Jan 2018 01:56:43 -0500 Subject: [PATCH 31/67] Welcome to 2018 --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 3ed9a1a..107c651 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2017 Michael Mintz +Copyright (c) 2018 Michael Mintz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 6c3a9dcf26ec46d6942c464dadd3397144ac159e Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Sun, 4 Feb 2018 16:40:11 -0500 Subject: [PATCH 32/67] Use "python setup.py develop" instead of "install" --- install.sh | 2 +- python3_install.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 6fd187b..fa1a62c 100755 --- a/install.sh +++ b/install.sh @@ -4,7 +4,7 @@ pip install --upgrade pip echo "Installing TensorPy for Python 2.7:" pip install -r requirements.txt --upgrade -python setup.py install +python setup.py develop value="$(uname)" if [ $value == "Linux" ] then diff --git a/python3_install.sh b/python3_install.sh index 4749bf2..b409877 100755 --- a/python3_install.sh +++ b/python3_install.sh @@ -4,7 +4,7 @@ pip3 install --upgrade pip echo "Installing TensorPy for Python 3:" pip3 install -r requirements.txt --upgrade -python3 setup.py install +python3 setup.py develop echo "Installing TensorFlow..." pip3 install --upgrade tensorflow echo "Downloading ImageNet Inception DB (for classifying images)..." From 5d6367126a501d6cba29e8e70b98cabe0f6d2d4f Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Sun, 4 Feb 2018 16:40:20 -0500 Subject: [PATCH 33/67] Update the ReadMe --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4292d20..84e946d 100644 --- a/README.md +++ b/README.md @@ -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) [![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) +[![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/) [![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) **Easy Image Classification with TensorFlow** From 2d99530244159f156b807b6369c3405ba187451e Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Sat, 4 Aug 2018 15:45:50 -0400 Subject: [PATCH 34/67] Update Dockerfile --- Dockerfile | 44 ++++++++++++++++++-------------------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3514060..6ad5690 100755 --- a/Dockerfile +++ b/Dockerfile @@ -1,50 +1,42 @@ # TensorPy Docker Image -FROM ubuntu:15.10 +FROM ubuntu:17.10 -#======================================= -# Install Python and Basic Python Tools -#======================================= -RUN apt-get update && apt-get install -y python python-pip python-setuptools \ - python-dev python-distribute python-virtualenv +#================================ +# Update apt-get package sources +#================================ +RUN apt-get update -#========================================= -# Install Bash Command Line Tools and Git -#========================================= +#================================================== +# Install Bash Command Line Tools, Python, and Git +#================================================== RUN apt-get -qy --no-install-recommends install \ + python \ + python-dev \ + python-pip \ + python-distribute \ + python-virtualenv \ + python-setuptools \ sudo \ unzip \ wget \ curl \ + libxi6 \ + libgconf-2-4 \ vim \ git-core \ && rm -rf /var/lib/apt/lists/* -#======================================== -# Add normal user with passwordless sudo -#======================================== -RUN sudo useradd seluser --shell /bin/bash --create-home \ - && sudo usermod -a -G sudo seluser \ - && echo 'ALL ALL = (ALL) NOPASSWD: ALL' >> /etc/sudoers - -#============================== -# Locale and encoding settings -#============================== -ENV LANGUAGE en_US.UTF-8 -ENV LANG ${LANGUAGE} -RUN locale-gen ${LANGUAGE} \ - && dpkg-reconfigure --frontend noninteractive locales - #============================== # Set up TensorFlow / TensorPy #============================== -COPY third_party/docker/docker_install.sh /TensorPy/docker_install.sh +COPY install.sh /TensorPy/install.sh COPY requirements.txt /TensorPy/ COPY setup.py /TensorPy/ COPY tensorpy /TensorPy/tensorpy/ COPY examples /TensorPy/examples/ COPY third_party/docker /TensorPy/third_party/docker/ COPY third_party/docker/run_docker_test.sh /TensorPy/ -RUN cd /TensorPy && ls && ./third_party/docker/docker_install.sh +RUN cd /TensorPy && ls && ./install.sh RUN cd /TensorPy && pip install -r requirements.txt #=================== From f2d35a1a3e2402abaa246e40101cf98cdf26308e Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Sat, 4 Aug 2018 15:50:16 -0400 Subject: [PATCH 35/67] Update and simplify install script --- install.sh | 14 ++++++-------- python3_install.sh | 12 ------------ 2 files changed, 6 insertions(+), 20 deletions(-) delete mode 100755 python3_install.sh diff --git a/install.sh b/install.sh index fa1a62c..0676a09 100755 --- a/install.sh +++ b/install.sh @@ -1,21 +1,19 @@ # Installs TensorPy, TensorFlow, ImageNet, and required dependancies -# (Made for Python 2.7) -pip install --upgrade pip -echo "Installing TensorPy for Python 2.7:" +python -m pip install --upgrade pip +echo "Installing TensorPy:" pip install -r requirements.txt --upgrade python setup.py develop value="$(uname)" -if [ $value == "Linux" ] +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.2.1-cp27-none-linux_x86_64.whl + export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.9.0-cp27-none-linux_x86_64.whl pip install --ignore-installed --upgrade $TF_BINARY_URL -elif [ $value == "Darwin" ] +elif [ $value = "Darwin" ] then echo "Initializing TensorFlow setup on a MAC..." - 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 + pip install --upgrade tensorflow else echo "Incompatible machine for TensorFlow. Exiting script..." fi diff --git a/python3_install.sh b/python3_install.sh deleted file mode 100755 index b409877..0000000 --- a/python3_install.sh +++ /dev/null @@ -1,12 +0,0 @@ -# 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 develop -echo "Installing TensorFlow..." -pip3 install --upgrade tensorflow -echo "Downloading ImageNet Inception DB (for classifying images)..." -python3 tensorpy/download_imagenet.py -exit From 84a7c2cf419e3fe040ab4dfcf77c6f4c4f015643 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Sat, 4 Aug 2018 15:50:53 -0400 Subject: [PATCH 36/67] Update requirements --- requirements.txt | 4 ++-- setup.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/requirements.txt b/requirements.txt index e5f2f52..afa93a6 100755 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ -requests==2.18.1 -six==1.10.0 +requests==2.19.1 +six==1.11.0 Pillow==4.1.1 BeautifulSoup4==4.6.0 -e . diff --git a/setup.py b/setup.py index 5f767cf..bc156a8 100644 --- a/setup.py +++ b/setup.py @@ -16,8 +16,8 @@ description='Easy Image Classification with TensorFlow!', license='The MIT License', install_requires=[ - 'requests==2.18.1', - 'six==1.10.0', + 'requests==2.19.1', + 'six==1.11.0', 'Pillow==4.1.1', 'BeautifulSoup4==4.6.0', ], From f413bbd6e307c1a0ab8b5a565ff006dd7d5db953 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Sat, 4 Aug 2018 15:56:17 -0400 Subject: [PATCH 37/67] Remove old install file --- third_party/docker/docker_install.sh | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100755 third_party/docker/docker_install.sh diff --git a/third_party/docker/docker_install.sh b/third_party/docker/docker_install.sh deleted file mode 100755 index 8edc900..0000000 --- a/third_party/docker/docker_install.sh +++ /dev/null @@ -1,12 +0,0 @@ -# Installs TensorPy, TensorFlow, ImageNet, and required dependancies -# (Special Docker edition!) - -pip install --upgrade pip -echo "Installing TensorPy..." -python setup.py install -echo "Initializing TensorFlow setup on an Ubuntu Docker machine..." -export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.10.0-cp27-none-linux_x86_64.whl -pip install $TF_BINARY_URL -echo "Downloading ImageNet (image database for classifying images)..." -python tensorpy/download_imagenet.py -exit From 9222c54444a0c8b157057e138124a1553f452176 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Sat, 4 Aug 2018 16:12:10 -0400 Subject: [PATCH 38/67] Move docker folder to integrations --- {third_party => integrations}/ReadMe.md | 2 +- {third_party => integrations}/docker/ReadMe.md | 0 {third_party => integrations}/docker/docker-entrypoint.sh | 0 {third_party => integrations}/docker/run_docker_test.sh | 0 4 files changed, 1 insertion(+), 1 deletion(-) rename {third_party => integrations}/ReadMe.md (59%) rename {third_party => integrations}/docker/ReadMe.md (100%) rename {third_party => integrations}/docker/docker-entrypoint.sh (100%) rename {third_party => integrations}/docker/run_docker_test.sh (100%) diff --git a/third_party/ReadMe.md b/integrations/ReadMe.md similarity index 59% rename from third_party/ReadMe.md rename to integrations/ReadMe.md index 287ae25..75f693f 100755 --- a/third_party/ReadMe.md +++ b/integrations/ReadMe.md @@ -1,3 +1,3 @@ -## Third-Party / Integrations +## Integrations This folder contains TensorPy integrations diff --git a/third_party/docker/ReadMe.md b/integrations/docker/ReadMe.md similarity index 100% rename from third_party/docker/ReadMe.md rename to integrations/docker/ReadMe.md diff --git a/third_party/docker/docker-entrypoint.sh b/integrations/docker/docker-entrypoint.sh similarity index 100% rename from third_party/docker/docker-entrypoint.sh rename to integrations/docker/docker-entrypoint.sh diff --git a/third_party/docker/run_docker_test.sh b/integrations/docker/run_docker_test.sh similarity index 100% rename from third_party/docker/run_docker_test.sh rename to integrations/docker/run_docker_test.sh From 9f180634a2cb6175eed621c78f9e8600aa2d36dc Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Sat, 4 Aug 2018 16:42:43 -0400 Subject: [PATCH 39/67] Update Dockerfile --- Dockerfile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6ad5690..5eddc8c 100755 --- a/Dockerfile +++ b/Dockerfile @@ -34,14 +34,13 @@ COPY requirements.txt /TensorPy/ COPY setup.py /TensorPy/ COPY tensorpy /TensorPy/tensorpy/ COPY examples /TensorPy/examples/ -COPY third_party/docker /TensorPy/third_party/docker/ -COPY third_party/docker/run_docker_test.sh /TensorPy/ +COPY integrations/docker/run_docker_test.sh /TensorPy/ RUN cd /TensorPy && ls && ./install.sh RUN cd /TensorPy && pip install -r requirements.txt #=================== # Create entrypoint #=================== -COPY third_party/docker/docker-entrypoint.sh / +COPY integrations/docker/docker-entrypoint.sh / ENTRYPOINT ["/docker-entrypoint.sh"] CMD ["/bin/bash"] From 329b5b1c08ccc453eb550d9f72a10d589ddba587 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Sat, 4 Aug 2018 18:36:09 -0400 Subject: [PATCH 40/67] Update the docs --- README.md | 14 +++----------- help_docs/pip_installation.md | 10 ++++++++-- help_docs/virtualenv_instructions.md | 9 ++++----- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 84e946d..a147c3b 100644 --- a/README.md +++ b/README.md @@ -11,14 +11,14 @@ (**Upgraded** since that video was 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 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). +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)** 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.) ## Setup Steps for Mac & Ubuntu/Linux -(**Windows & Docker users**: See the **[Docker ReadMe](https://github.com/TensorPy/TensorPy/blob/master/third_party/docker/ReadMe.md)** for running on a Docker machine. Windows requires Docker to run TensorFlow.) +(**Windows & Docker users**: See the **[Docker ReadMe](https://github.com/TensorPy/TensorPy/blob/master/integrations/docker/ReadMe.md)** for running on a Docker machine. Windows requires Docker to run TensorFlow.) #### **Step 1:** Create and activate a virtual environment named "tensorpy" @@ -33,18 +33,12 @@ cd TensorPy #### **Step 3:** Install TensorPy, TensorFlow, and ImageNet/Inception -For **Python 2.7** users, use **[install.sh](https://github.com/TensorPy/TensorPy/blob/master/install.sh)** to install everything you need. +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 (NOTE: Run times may vary depending on your Internet connection and computer's CPU speed.) @@ -81,8 +75,6 @@ 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 diff --git a/help_docs/pip_installation.md b/help_docs/pip_installation.md index 158a808..6ecdaad 100755 --- a/help_docs/pip_installation.md +++ b/help_docs/pip_installation.md @@ -1,13 +1,19 @@ ### Pip Installation Instructions -Ubuntu/Linux +Ubuntu/Linux: ```bash sudo apt-get install python-pip python-dev ``` -Mac OS X +Mac OS X: ```bash sudo easy_install pip ``` + +OR + +```bash +python -m pip install -U pip +``` diff --git a/help_docs/virtualenv_instructions.md b/help_docs/virtualenv_instructions.md index 2452237..692f620 100755 --- a/help_docs/virtualenv_instructions.md +++ b/help_docs/virtualenv_instructions.md @@ -1,15 +1,15 @@ ### Virtual Environment Setup Tutorial -First: +First, install virtualenv / virtualenvwrapper: ```bash -sudo pip install virtualenv -sudo pip install virtualenvwrapper +python -m pip install virtualenv +python -m pip install virtualenvwrapper export WORKON_HOME=$HOME/.virtualenvs source /usr/local/bin/virtualenvwrapper.sh ``` -Next, follow the command depending on the system you're using: +If you add ``source /usr/local/bin/virtualenvwrapper.sh`` to your local bash file (``~/.bash_profile`` on Mac, ``~/.bashrc`` on Linux), virtualenvwrapper commands will be available to you whenever you open a new command prompt. You can then use the following commands to make those changes active. Mac users: ``source ~/.bash_profile`` Linux users: ``source ~/.bashrc`` @@ -28,7 +28,6 @@ deactivate You can always jump back in later: -(If you're using ``virtualenvwrapper``): ```bash workon tensorpy ``` From 46f224ba1203c48605fc6179fe8e7d405c5df88c Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Sat, 4 Aug 2018 18:44:17 -0400 Subject: [PATCH 41/67] Version 1.2.0 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index bc156a8..1f3db68 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setup( name='tensorpy', - version='1.1.0', + version='1.2.0', url='http://tensorpy.com', author='Michael Mintz', author_email='mdmintz@gmail.com', From 96b9e52c5b37fbd27299d62784094b69a62901df Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Sat, 4 Aug 2018 19:25:02 -0400 Subject: [PATCH 42/67] Update .gitignore --- .gitignore | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.gitignore b/.gitignore index 091919c..83ed8e8 100644 --- a/.gitignore +++ b/.gitignore @@ -63,6 +63,11 @@ instance/ # Sphinx documentation docs/_build/ +# py.test +.cache/* +.pytest_cache/* +.pytest_config + # PyBuilder target/ From b6e1df3ad4b3feee64e4fc743c2711faf61b5161 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Wed, 24 Oct 2018 00:33:30 -0400 Subject: [PATCH 43/67] Update requirements --- requirements.txt | 6 +++--- setup.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/requirements.txt b/requirements.txt index afa93a6..b03feca 100755 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ -requests==2.19.1 -six==1.11.0 +six +requests==2.20.0 Pillow==4.1.1 -BeautifulSoup4==4.6.0 +BeautifulSoup4>=4.6.0 -e . diff --git a/setup.py b/setup.py index 1f3db68..91599dc 100644 --- a/setup.py +++ b/setup.py @@ -16,10 +16,10 @@ description='Easy Image Classification with TensorFlow!', license='The MIT License', install_requires=[ - 'requests==2.19.1', - 'six==1.11.0', + 'six', + 'requests==2.20.0', 'Pillow==4.1.1', - 'BeautifulSoup4==4.6.0', + 'BeautifulSoup4>=4.6.0', ], packages=['tensorpy'], entry_points={ From 616a4afe24e34c7f2dcf7236d9b29bc7e981b7ee Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Wed, 24 Oct 2018 00:33:49 -0400 Subject: [PATCH 44/67] Version 1.3.0 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 91599dc..e448db9 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setup( name='tensorpy', - version='1.2.0', + version='1.3.0', url='http://tensorpy.com', author='Michael Mintz', author_email='mdmintz@gmail.com', From 3814fab12b07f16ef391983b90d60c235bf24f5e Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Wed, 24 Oct 2018 00:59:20 -0400 Subject: [PATCH 45/67] Sync setup file --- setup.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index e448db9..d846e62 100644 --- a/setup.py +++ b/setup.py @@ -5,16 +5,29 @@ """ from setuptools import setup, find_packages # noqa +from os import path + + +this_directory = path.abspath(path.dirname(__file__)) +long_description = None +try: + with open(path.join(this_directory, 'README.md'), 'rb') as f: + long_description = f.read().decode('utf-8') +except IOError: + long_description = 'Easy Image Classification with TensorFlow!' setup( name='tensorpy', version='1.3.0', - url='http://tensorpy.com', + description='Easy Image Classification with TensorFlow!', + long_description=long_description, + long_description_content_type='text/markdown', + url='https://github.com/TensorPy/TensorPy', + platforms=["Linux", "Unix", "Mac OS-X"], author='Michael Mintz', author_email='mdmintz@gmail.com', maintainer='Michael Mintz', - description='Easy Image Classification with TensorFlow!', - license='The MIT License', + license="MIT", install_requires=[ 'six', 'requests==2.20.0', From 320f6476bcc91cc2e4a9534262c717d8cb995e03 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Wed, 24 Oct 2018 01:00:12 -0400 Subject: [PATCH 46/67] Version 1.3.1 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index d846e62..dfdc789 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ setup( name='tensorpy', - version='1.3.0', + version='1.3.1', description='Easy Image Classification with TensorFlow!', long_description=long_description, long_description_content_type='text/markdown', From 8c7259e733333da618f0217bdfe5aceed8e844f0 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Sun, 30 Jun 2019 21:05:34 -0400 Subject: [PATCH 47/67] Fix image converter --- tensorpy/image_base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tensorpy/image_base.py b/tensorpy/image_base.py index 237b6bc..faf1a80 100644 --- a/tensorpy/image_base.py +++ b/tensorpy/image_base.py @@ -26,14 +26,14 @@ def convert_image_file_to_jpg(file_name): outfile = f + ".jpg" if infile != outfile: try: - Image.open(infile).convert('RGBA').save(outfile, "JPEG") + Image.open(infile).convert('RGB').save(outfile, "JPEG") except IOError: raise Exception("Cannot convert %s to jpg!" % file_name) def load_image_from_url(image_url): response = requests.get(image_url) - image = Image.open(StringIO(response.content)).convert('RGBA') + image = Image.open(StringIO(response.content)).convert('RGB') return image From 339131966de1c46e87d2ec14afaf6b827324b34f Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Sun, 30 Jun 2019 21:06:11 -0400 Subject: [PATCH 48/67] Replace deprecated method with new version --- tensorpy/classify_image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorpy/classify_image.py b/tensorpy/classify_image.py index 40a05a8..459f01a 100644 --- a/tensorpy/classify_image.py +++ b/tensorpy/classify_image.py @@ -13,7 +13,7 @@ os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' FLAGS = tf.app.flags.FLAGS -tf.logging.set_verbosity(tf.logging.ERROR) +tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR) tf.app.flags.DEFINE_string( 'model_dir', settings.IMAGENET_FOLDER, """Path to classify_image_graph_def.pb, """ From bdc20850f99e0090c72f5cc474ad72494eee13e9 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Sun, 30 Jun 2019 21:14:07 -0400 Subject: [PATCH 49/67] Replace deprecated methods --- tensorpy/classify_image.py | 2 +- tensorpy/download_imagenet.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tensorpy/classify_image.py b/tensorpy/classify_image.py index 459f01a..2c20196 100644 --- a/tensorpy/classify_image.py +++ b/tensorpy/classify_image.py @@ -126,4 +126,4 @@ def external_run(image): if __name__ == '__main__': - tf.app.run() + tf.compat.v1.app.run() diff --git a/tensorpy/download_imagenet.py b/tensorpy/download_imagenet.py index ab425e7..f7bf534 100644 --- a/tensorpy/download_imagenet.py +++ b/tensorpy/download_imagenet.py @@ -43,4 +43,4 @@ def main(_): maybe_download_and_extract() -tf.app.run() +tf.compat.v1.app.run() From 5eb0bec7e4c4e9a7f02f637e23ea876ea595ab71 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Sun, 30 Jun 2019 21:15:02 -0400 Subject: [PATCH 50/67] Update requirements --- install.sh | 2 +- requirements.txt | 6 +++--- setup.py | 5 +++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/install.sh b/install.sh index 0676a09..2062c23 100755 --- a/install.sh +++ b/install.sh @@ -8,7 +8,7 @@ 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.9.0-cp27-none-linux_x86_64.whl + export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.14.0-cp27-none-linux_x86_64.whl pip install --ignore-installed --upgrade $TF_BINARY_URL elif [ $value = "Darwin" ] then diff --git a/requirements.txt b/requirements.txt index b03feca..643dffc 100755 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ six -requests==2.20.0 -Pillow==4.1.1 +tensorflow>=1.14.0 +requests>=2.22.0 +Pillow>=6.0.0 BeautifulSoup4>=4.6.0 --e . diff --git a/setup.py b/setup.py index dfdc789..0d24f1e 100644 --- a/setup.py +++ b/setup.py @@ -30,8 +30,9 @@ license="MIT", install_requires=[ 'six', - 'requests==2.20.0', - 'Pillow==4.1.1', + 'tensorflow>=1.14.0', + 'requests>=2.22.0', + 'Pillow>=6.0.0', 'BeautifulSoup4>=4.6.0', ], packages=['tensorpy'], From 7c277d0534e7ba45da184af489687073ecd3be75 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Sun, 30 Jun 2019 21:15:20 -0400 Subject: [PATCH 51/67] Version 1.4.0 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 0d24f1e..b56063d 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ setup( name='tensorpy', - version='1.3.1', + version='1.4.0', description='Easy Image Classification with TensorFlow!', long_description=long_description, long_description_content_type='text/markdown', From d0d7d0a078b94e943f7d4d5722ad7e98444f7a26 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Fri, 5 Jul 2019 15:31:25 -0400 Subject: [PATCH 52/67] Use Pillow>=6.1.0 --- requirements.txt | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 643dffc..071d028 100755 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ six tensorflow>=1.14.0 requests>=2.22.0 -Pillow>=6.0.0 +Pillow>=6.1.0 BeautifulSoup4>=4.6.0 diff --git a/setup.py b/setup.py index b56063d..5d887b8 100644 --- a/setup.py +++ b/setup.py @@ -32,7 +32,7 @@ 'six', 'tensorflow>=1.14.0', 'requests>=2.22.0', - 'Pillow>=6.0.0', + 'Pillow>=6.1.0', 'BeautifulSoup4>=4.6.0', ], packages=['tensorpy'], From b222f719e80981de4fc405f2683b9757988276b7 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Fri, 5 Jul 2019 15:32:07 -0400 Subject: [PATCH 53/67] Fix indentation --- tensorpy/classify.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tensorpy/classify.py b/tensorpy/classify.py index 39ff08e..518e97e 100644 --- a/tensorpy/classify.py +++ b/tensorpy/classify.py @@ -124,9 +124,9 @@ def main(): break if images_classified >= settings.MAX_IMAGES_PER_PAGE: - print("\n(NOTE: Exceeded page classification limit " - "of %d images per URL! Stopping early.)" % ( - settings.MAX_IMAGES_PER_PAGE)) + print("\n(NOTE: Exceeded page classification limit " + "of %d images per URL! Stopping early.)" % ( + settings.MAX_IMAGES_PER_PAGE)) if images_classified == 0: print("\nCould not find images to classify on the page! " From 1f70a032b3c1de64658aab406b8e86381993f91c Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Fri, 5 Jul 2019 15:34:53 -0400 Subject: [PATCH 54/67] Better image I/O --- tensorpy/image_base.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tensorpy/image_base.py b/tensorpy/image_base.py index faf1a80..98aa7c1 100644 --- a/tensorpy/image_base.py +++ b/tensorpy/image_base.py @@ -14,9 +14,9 @@ def get_image_file_dimensions(file_name): - image = Image.open(file_name) - image_dimensions = image.size # (width, height) tuple - return image_dimensions + with Image.open(file_name) as image: + image_dimensions = image.size # (width, height) tuple + return image_dimensions def convert_image_file_to_jpg(file_name): @@ -26,15 +26,17 @@ def convert_image_file_to_jpg(file_name): outfile = f + ".jpg" if infile != outfile: try: - Image.open(infile).convert('RGB').save(outfile, "JPEG") + with Image.open(infile) as image: + image.convert('RGB').save(outfile, "JPEG") except IOError: raise Exception("Cannot convert %s to jpg!" % file_name) def load_image_from_url(image_url): response = requests.get(image_url) - image = Image.open(StringIO(response.content)).convert('RGB') - return image + with Image.open(StringIO(response.content)) as image: + image.convert('RGB') + return image def get_image_dimensions(image): From d4af72529f3bf50d07dc6557136efc9858539ac7 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Fri, 5 Jul 2019 15:35:09 -0400 Subject: [PATCH 55/67] Version 1.4.1 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 5d887b8..5f24008 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ setup( name='tensorpy', - version='1.4.0', + version='1.4.1', description='Easy Image Classification with TensorFlow!', long_description=long_description, long_description_content_type='text/markdown', From ad8542919f8afdbeb02a13d1fa77c21113b5e46f Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Sat, 10 Aug 2019 23:31:51 -0400 Subject: [PATCH 56/67] Use tensorflow==1.14.0 --- requirements.txt | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 071d028..9a8a026 100755 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ six -tensorflow>=1.14.0 +tensorflow==1.14.0 requests>=2.22.0 Pillow>=6.1.0 BeautifulSoup4>=4.6.0 diff --git a/setup.py b/setup.py index 5f24008..9deac6b 100644 --- a/setup.py +++ b/setup.py @@ -30,7 +30,7 @@ license="MIT", install_requires=[ 'six', - 'tensorflow>=1.14.0', + 'tensorflow==1.14.0', 'requests>=2.22.0', 'Pillow>=6.1.0', 'BeautifulSoup4>=4.6.0', From e1138f22fe128e167064f472500d571835ee9614 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Sat, 10 Aug 2019 23:32:07 -0400 Subject: [PATCH 57/67] Version 1.4.2 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 9deac6b..c70f308 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ setup( name='tensorpy', - version='1.4.1', + version='1.4.2', description='Easy Image Classification with TensorFlow!', long_description=long_description, long_description_content_type='text/markdown', From b137a25745cef4a1172a8597d7468afa5956ae27 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Fri, 25 Sep 2020 16:54:02 -0400 Subject: [PATCH 58/67] Update Python requirements --- requirements.txt | 8 ++++---- setup.py | 14 ++++++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/requirements.txt b/requirements.txt index 9a8a026..a6995c3 100755 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ -six -tensorflow==1.14.0 -requests>=2.22.0 -Pillow>=6.1.0 +tensorflow==1.15.4 +six>=1.11.0 +requests>=2.18.4 +Pillow==5.4.1 BeautifulSoup4>=4.6.0 diff --git a/setup.py b/setup.py index c70f308..2cccdac 100644 --- a/setup.py +++ b/setup.py @@ -28,11 +28,17 @@ author_email='mdmintz@gmail.com', maintainer='Michael Mintz', license="MIT", + classifiers=[ + "Programming Language :: Python :: 3.5", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + ], + python_requires='>=3.5, <3.8', install_requires=[ - 'six', - 'tensorflow==1.14.0', - 'requests>=2.22.0', - 'Pillow>=6.1.0', + 'tensorflow==1.15.4', + 'six>=1.11.0', + 'requests>=2.18.4', + 'Pillow==5.4.1', 'BeautifulSoup4>=4.6.0', ], packages=['tensorpy'], From 36bb5f553f0488b8eba7c0b70c7a35ffccb47dbb Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Fri, 25 Sep 2020 16:55:38 -0400 Subject: [PATCH 59/67] Add Easy-Deploy / Easy-Publish --- setup.py | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 2cccdac..394a77c 100644 --- a/setup.py +++ b/setup.py @@ -5,17 +5,47 @@ """ from setuptools import setup, find_packages # noqa -from os import path +import os +import sys -this_directory = path.abspath(path.dirname(__file__)) +this_directory = os.path.abspath(os.path.dirname(__file__)) long_description = None try: - with open(path.join(this_directory, 'README.md'), 'rb') as f: + with open(os.path.join(this_directory, 'README.md'), 'rb') as f: long_description = f.read().decode('utf-8') except IOError: long_description = 'Easy Image Classification with TensorFlow!' +if sys.argv[-1] == 'publish': + reply = None + input_method = input + if not sys.version_info[0] >= 3: + input_method = raw_input # noqa + reply = str(input_method( + '>>> Confirm release PUBLISH to PyPI? (yes/no): ')).lower().strip() + if reply == 'yes': + print("\n*** Checking code health with flake8:\n") + flake8_status = os.system("flake8 --exclude=temp") + if flake8_status != 0: + print("\nWARNING! Fix flake8 issues before publishing to PyPI!\n") + sys.exit() + else: + print("*** No flake8 issues detected. Continuing...") + print("\n*** Rebuilding distribution packages: ***\n") + os.system('rm -f dist/*.egg; rm -f dist/*.tar.gz; rm -f dist/*.whl') + os.system('python setup.py sdist bdist_wheel') # Create new tar/wheel + print("\n*** Installing twine: *** (Required for PyPI uploads)\n") + os.system("python -m pip install --upgrade 'twine>=1.15.0'") + print("\n*** Installing tqdm: *** (Required for PyPI uploads)\n") + os.system("python -m pip install --upgrade 'tqdm>=4.49.0'") + print("\n*** Publishing The Release to PyPI: ***\n") + os.system('python -m twine upload dist/*') # Requires ~/.pypirc Keys + print("\n*** The Release was PUBLISHED SUCCESSFULLY to PyPI! :) ***\n") + else: + print("\n>>> The Release was NOT PUBLISHED to PyPI! <<<\n") + sys.exit() + setup( name='tensorpy', version='1.4.2', From a417458fd24ab197b590325a786e17861918751b Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Fri, 25 Sep 2020 16:57:22 -0400 Subject: [PATCH 60/67] Print the filepath for ImageNet Inception DB downloads --- tensorpy/download_imagenet.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tensorpy/download_imagenet.py b/tensorpy/download_imagenet.py index f7bf534..1dd49b3 100644 --- a/tensorpy/download_imagenet.py +++ b/tensorpy/download_imagenet.py @@ -26,6 +26,7 @@ def maybe_download_and_extract(): os.makedirs(dest_directory) filename = DATA_URL.split('/')[-1] filepath = os.path.join(dest_directory, filename) + print("ImageNet Inception DB filepath: %s" % filepath) if not os.path.exists(filepath): def _progress(count, block_size, total_size): sys.stdout.write('\r>> Downloading %s %.1f%%' % ( From 0eb02b6e88e40f957632b0aa78ab6ccdb3a7692c Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Fri, 25 Sep 2020 16:57:41 -0400 Subject: [PATCH 61/67] Update the ReadMe --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a147c3b..86c9bee 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,10 @@ (**[Watch the 2-minute tutorial on YouTube](https://www.youtube.com/watch?v=lVtzaHcUE7Q)**) -(**Upgraded** since that video was released!) +### Requirements: + +* A Mac or Linux machine +* Python 3.5, 3.6, or 3.7 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)** for details). From 4389e2975422a5821ae66a90e5e082a192b57a2c Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Fri, 25 Sep 2020 16:58:45 -0400 Subject: [PATCH 62/67] Version 1.5.0 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 394a77c..5344053 100644 --- a/setup.py +++ b/setup.py @@ -48,7 +48,7 @@ setup( name='tensorpy', - version='1.4.2', + version='1.5.0', description='Easy Image Classification with TensorFlow!', long_description=long_description, long_description_content_type='text/markdown', From 6af417b3b28b9ab97ab915ba0200264e52526284 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Fri, 25 Sep 2020 17:29:54 -0400 Subject: [PATCH 63/67] Update the ReadMe --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 86c9bee..56b21ec 100644 --- a/README.md +++ b/README.md @@ -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) [![Python version](https://img.shields.io/badge/python-2.7,_3.*-22AADD.svg "Python version")](https://docs.python.org/2/) [![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-3.5,_3.6,_3.7-22AADD.svg "Python version")](https://docs.python.org/2/) [![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) **Easy Image Classification with TensorFlow** From 06d01997a1f98b8cfe74e90148310bdbc006acb3 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Fri, 25 Sep 2020 17:52:58 -0400 Subject: [PATCH 64/67] Update Python dependencies --- requirements.txt | 9 +++++---- setup.py | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/requirements.txt b/requirements.txt index a6995c3..ae3e67b 100755 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ tensorflow==1.15.4 -six>=1.11.0 -requests>=2.18.4 -Pillow==5.4.1 -BeautifulSoup4>=4.6.0 +pip>=20.2.3 +six>=1.15.0 +requests>=2.24.0 +Pillow==7.2.0 +beautifulsoup4==4.9.1 diff --git a/setup.py b/setup.py index 5344053..6347a3e 100644 --- a/setup.py +++ b/setup.py @@ -66,10 +66,11 @@ python_requires='>=3.5, <3.8', install_requires=[ 'tensorflow==1.15.4', - 'six>=1.11.0', - 'requests>=2.18.4', - 'Pillow==5.4.1', - 'BeautifulSoup4>=4.6.0', + 'pip>=20.2.3', + 'six>=1.15.0', + 'requests>=2.24.0', + 'Pillow==7.2.0', + 'beautifulsoup4==4.9.1', ], packages=['tensorpy'], entry_points={ From 47a52141b7699bb5ec04f4eb294d000ab1296efc Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Fri, 25 Sep 2020 17:53:36 -0400 Subject: [PATCH 65/67] Version 1.6.0 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 6347a3e..21fb0ad 100644 --- a/setup.py +++ b/setup.py @@ -48,7 +48,7 @@ setup( name='tensorpy', - version='1.5.0', + version='1.6.0', description='Easy Image Classification with TensorFlow!', long_description=long_description, long_description_content_type='text/markdown', From 25f6bbd05caf37b883f4a30b1a58ee08c74bf9f1 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Sat, 26 Sep 2020 19:58:44 -0400 Subject: [PATCH 66/67] Update a Python dependency: beautifulsoup4==4.9.2 --- requirements.txt | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index ae3e67b..5f4fae2 100755 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,4 @@ pip>=20.2.3 six>=1.15.0 requests>=2.24.0 Pillow==7.2.0 -beautifulsoup4==4.9.1 +beautifulsoup4==4.9.2 diff --git a/setup.py b/setup.py index 21fb0ad..064998f 100644 --- a/setup.py +++ b/setup.py @@ -70,7 +70,7 @@ 'six>=1.15.0', 'requests>=2.24.0', 'Pillow==7.2.0', - 'beautifulsoup4==4.9.1', + 'beautifulsoup4==4.9.2', ], packages=['tensorpy'], entry_points={ From 53adc31d3ae38dd6a4f5e35f41c7f4d0b16e0de5 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Sat, 26 Sep 2020 19:59:01 -0400 Subject: [PATCH 67/67] Version 1.6.1 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 064998f..863853e 100644 --- a/setup.py +++ b/setup.py @@ -48,7 +48,7 @@ setup( name='tensorpy', - version='1.6.0', + version='1.6.1', description='Easy Image Classification with TensorFlow!', long_description=long_description, long_description_content_type='text/markdown',