Generate image dataset from one folder, label each image one by one, for machine learning via tensorflow

This is an update for previous post.
http://lengerrong.blogspot.com/2017/04/create-your-own-dataset-for-machine.html

It is hard to collect enough images for your machine traning.
So I update this post to append images once you find some to your existed dataset.
All you need to do is copy your images to a folder and run the python script.

Of cause, you have to label each image while running the python script.
Below python script just have two label, 0 means cat, 1 means dog.
You can add more labels by just modify blue codes.

How to fix tf.nn.in_top_k out of range issue: tensorflow.python.framework.errors_impl.InvalidArgumentError: targets[0] is out of range

tensorflow.python.framework.errors_impl.InvalidArgumentError: targets[0] is out of range
         [[Node: InTopK = InTopK[T=DT_INT32, k=1, _device="/job:localhost/replica:0/task:0/cpu:0"](softmax_linear/softmax_linear, Reshape_1)]]

Caused by op u'InTopK', defined at:


主的道是公平的 当回头得以存活



“恶人若回头离开所做的一切罪恶,谨守我一切的律例,行正直与合理的事,他必定存活,不致死亡。  (以西结书 18:21 和合本)
“But if a wicked person turns away from all the sins they have committed and keeps all my decrees and does what is just and right, that person will surely live; they will not die.  (Ezekiel 18:21 NIV)
他所犯的一切罪过都不被记念,因所行的义,他必存活。  (以西结书 18:22 和合本)
None of the offenses they have committed will be remembered against them. Because of the righteous things they have done, they will live.  (Ezekiel 18:22 NIV)
主耶和华说:恶人死亡,岂是我喜悦的吗?不是喜悦他回头离开所行的道存活吗?  (以西结书 18:23 和合本)
Do I take any pleasure in the death of the wicked? declares the Sovereign Lord . Rather, am I not pleased when they turn from their ways and live?  (Ezekiel 18:23 NIV)
义人若转离义行而作罪孽,照着恶人所行一切可憎的事而行,他岂能存活吗?他所行的一切义都不被记念;他必因所犯的罪、所行的恶死亡。 (以西结书 18:24 和合本)
“But if a righteous person turns from their righteousness and commits sin and does the same detestable things the wicked person does, will they live? None of the righteous things that person has done will be remembered. Because of the unfaithfulness they are guilty of and because of the sins they have committed, they will die.  (Ezekiel 18:24 NIV)
“你们还说:‘主的道不公平!’以色列家啊,你们当听,我的道岂不公平吗?你们的道岂不是不公平吗?  (以西结书 18:25 和合本)
“Yet you say, ‘The way of the Lord is not just.’ Hear, you Israelites: Is my way unjust? Is it not your ways that are unjust?  (Ezekiel 18:25 NIV)
义人若转离义行而作罪孽死亡,他是因所作的罪孽死亡。  (以西结书 18:26 和合本)
If a righteous person turns from their righteousness and commits sin, they will die for it; because of the sin they have committed they will die.  (Ezekiel 18:26 NIV)
再者,恶人若回头离开所行的恶,行正直与合理的事,他必将性命救活了。  (以西结书 18:27 和合本)
But if a wicked person turns away from the wickedness they have committed and does what is just and right, they will save their life.  (Ezekiel 18:27 NIV)
因为他思量,回头离开所犯的一切罪过,必定存活,不致死亡。  (以西结书 18:28 和合本)
Because they consider all the offenses they have committed and turn away from them, that person will surely live; they will not die.  (Ezekiel 18:28 NIV)
以色列家还说:‘主的道不公平!’以色列家啊,我的道岂不公平吗?你们的道岂不是不公平吗?” (以西结书 18:29 和合本)
Yet the Israelites say, ‘The way of the Lord is not just.’ Are my ways unjust, people of Israel? Is it not your ways that are unjust?  (Ezekiel 18:29 NIV)
所以主耶和华说:“以色列家啊,我必按你们各人所行的审判你们。你们当回头离开所犯的一切罪过。这样,罪孽必不使你们败亡。  (以西结书 18:30 和合本)
“Therefore, you Israelites, I will judge each of you according to your own ways, declares the Sovereign Lord . Repent! Turn away from all your offenses; then sin will not be your downfall.  (Ezekiel 18:30 NIV)
你们要将所犯的一切罪过尽行抛弃,自做一个新心和新灵。以色列家啊,你们何必死亡呢?  (以西结书 18:31 和合本)
Rid yourselves of all the offenses you have committed, and get a new heart and a new spirit. Why will you die, people of Israel?  (Ezekiel 18:31 NIV)
主耶和华说:我不喜悦那死人之死,所以你们当回头而存活。” (以西结书 18:32 和合本)
For I take no pleasure in the death of anyone, declares the Sovereign Lord . Repent and live!  (Ezekiel 18:32 NIV)


我们不致消灭,是出于耶和华诸般的慈爱;是因他的怜悯不致断绝。 (耶利米哀歌 3:22 和合本)
Because of the Lord ’s great love we are not consumed, for his compassions never fail.  (Lamentations 3:22 NIV)
每早晨,这都是新的;你的诚实极其广大! (耶利米哀歌 3:23 和合本)
They are new every morning; great is your faithfulness.  (Lamentations 3:23 NIV)
我心里说:耶和华是我的分,因此,我要仰望他。 (耶利米哀歌 3:24 和合本)
I say to myself, “The Lord is my portion; therefore I will wait for him.”  (Lamentations 3:24 NIV)
凡等候耶和华,心里寻求他的,耶和华必施恩给他。 (耶利米哀歌 3:25 和合本)
The Lord is good to those whose hope is in him, to the one who seeks him;  (Lamentations 3:25 NIV)
人仰望耶和华,静默等候他的救恩,这原是好的。 (耶利米哀歌 3:26 和合本)
it is good to wait quietly for the salvation of the Lord .  (Lamentations 3:26 NIV)
人在幼年负轭,这原是好的。 (耶利米哀歌 3:27 和合本)
It is good for a man to bear the yoke while he is young.  (Lamentations 3:27 NIV)


python show an image via subprocess.Popen

import tensorflow as tf
import Image
import os
import subprocess

def main(argv): 
  folder = argv[0]
  if (len(argv) > 1):
    if tf.gfile.Exists(argv[1]):
      folder = argv[1]
    else:
      print ('%s not existed' % argv[1])
      return
  else:
    print ("please input training image data folder path")
    return
  for f in tf.gfile.ListDirectory(folder):
    filepath = os.path.join(folder, f)
    try:
      im = Image.open(filepath)
      p = subprocess.Popen(["display", filepath])
      label = raw_input("please label the image, 0 means cat, 1 means dog:")
      p.kill()
    except Exception, e:
      print (e)

python Thread.join & setDaemon sample

prototype:

join([timeout]) # wait the child thread complete

setDaemon(True) # once the daemon thread complete, the child thread complete too.

from threading import Thread
from PIL import Image

    class ImageThread(Thread):
      def __init__(self, filepath):
        Thread.__init__(self)
        self.filepath = filepath
        self.openresult = 0

      def run(self):
        try:
          im = Image.open(self.filepath)
          im.show()
          self.openresult = 1
        except Exception, e:
          print (e)

    imt = ImageThread('image.gif')
    imt.setDaemon(True) # should set before start
    imt.start()
    imt.join(10) # wait 10 seconds

Solution for no image display after call Image.show via python

simple python code like:
 
from PIL import Image   
image = Image.open('image.gif' 
image.show() 

no image display while running on ubuntu system.

The easy solution is:
sudo apt-get install imagemagick

fixed: embedded-redis: Unable to run on macOS Sonoma

Issue you might see below error while trying to run embedded-redis for your testing on your macOS after you upgrade to Sonoma. java.la...