Exemplo n.º 1
0
# Run session
with tf.Session() as sess:

    if is_saved_model_exist():
        pass
    else:
        
        # Initiale mode must be 'training'
        if is_test_mode:
            raise ValueError("Test mode is not valid when a trained module doesn't exist")
        
        # Training configuration
        batch_size = config.batch_size
        
        # Get a batch from the reader
        reader = ImageReader(images_dir, labels_dir, data_list_file, (config.image_height, config.image_width), 
                             False, False, 0)
        inputs = reader.dequeue(batch_size)
        image_batch = inputs[0] #batch size x height x width x 3
        label_batch = inputs[1] #batch size x height x width x 1
        
        # Load the model
        mapping = model.get_mapping_model(image_batch, name='mapping')
        
        # Initialize variables
        sess.run(tf.global_variables_initializer())
            
    # Loss and optimizer
    loss = model.loss(mapping, label_batch)
    optimizer = model.optimizer(loss)
    
    # Run the data queue
Exemplo n.º 2
0
import matplotlib.pyplot as plt
from PIL import Image

from imageReader import ImageReader

img = Image.open("./rg.png")

imr = ImageReader()
squares = imr.transfromImage(img, 15)

imgplot = plt.imshow(squares)
plt.show()
Exemplo n.º 3
0
def testModel(model, X, y, nGesture):
    nCorrect = 0
    nGuess = np.zeros(nGesture)
    for i in range(0, X.shape[0]):
        guess = nn.infer(X[i], model)
        nGuess[guess] = nGuess[guess] + 1
        #print "Guess", i, ":", guess, "Actual :", np.argmax(y[i])
        nCorrect = nCorrect + y[i][guess]
    #print nCorrect, "correct out of", X.shape[0]
    print "Accuracy :", nCorrect * 1.0 / X.shape[0] * 100.0, "%"
    print "nGuesses :", nGuess


if __name__ == "__main__":
    imageReader = ImageReader()
    nHiddenLayer = 3
    hiddenLayerSize = 1000
    lmbda = 0.01
    maxIter = 400

    hiddenLayerSizes = []
    for i in range(0, nHiddenLayer):
        hiddenLayerSizes.append(hiddenLayerSize)
    layerSizes = [imageReader.n] + hiddenLayerSizes + [imageReader.nGesture]

    (X, y), (Xv, yv) = imageReader.readImages()
    print len(X), "training data"
    print len(Xv), "test data"
    model = trainModel(layerSizes, X, y, lmbda, maxIter)
Exemplo n.º 4
0
    #    temp = cv2.subtract(img,temp)
    #    skel = cv2.bitwise_or(skel,temp)
    #    img = eroded.copy()

    #    zeros = size - cv2.countNonZero(img)
    #    if zeros==size:
    #        done = True

    #cv2.imshow("skel",skel)
    #D* Lite Method ---------------------------------------------
    newHeight = int(height * 0.1)
    newWidth = int(width * 0.1)
    dliteimage = cv2.resize(agvcmap.getImage(), (newWidth, newHeight))
    cv2.imwrite('AGVCmap2.bmp', dliteimage)
    robot = Robot(TEG.x, TEG.y, TEG.radius * 2)
    imageMap = ImageReader()
    imageMap.loadFile("AGVCmap2.bmp")
    mapper.initalize(imageMap, robot)
    moveGrid = imageMap.convertToGrid().copy()

    ##goal = point(3,17)
    testdivider = 1
    goal = point(int(newHeight / testdivider * 0.8),
                 int(newWidth / testdivider * 0.8))
    #cv2.waitKey(0)

    ##mapper.printMoveGrid()

    print "STARTIN LOOP"
    moveId = 0
    Xlength = mapper.grid.shape[0] / testdivider
Exemplo n.º 5
0
	def calculatePath(self):
		height = self.map.height
		width = self.map.width
		newHeight = int(height*0.1)
		newWidth = int(width*0.1)
		dliteimage = cv2.resize(self.map.getImage(),(newWidth,newHeight))
		cv2.imwrite('AGVCmap2.bmp', dliteimage)
		robot = Robot(self.vehicle.x,self.vehicle.y,self.vehicle.radius*2)
		imageMap = ImageReader()
		imageMap.loadFile("AGVCmap2.bmp")
		mapper.initalize(imageMap,robot)
		moveGrid = imageMap.convertToGrid().copy()

		##goal = point(3,17)
		testdivider = 1
		self.goal = point(int(newHeight/testdivider*0.8),int(newWidth/testdivider*0.8))
		#cv2.waitKey(0)

		##mapper.printMoveGrid()

		print "STARTIN LOOP"
		moveId=0
		Xlength = mapper.grid.shape[0]/testdivider
		Ylength = mapper.grid.shape[1]/testdivider
		#dstar = dstar3.DStar(Xlength,Ylength,goal)
		dstar = dlite.Dlite(Xlength,Ylength,self.goal,robot)
		print "Entering Loop"
		testvar = 0

		#for i in range(10):
		while (robot.y != self.goal.y or robot.x != self.goal.x) :
			if testvar%2 == 0:
				newObs = obstacle.Obstacle(random.randint(0,height),random.randint(0,width), 40)
				self.map.placeObstacle(newObs,3)
				self.obsList.append(newObs)
				#Place obstacles on map
				self.map.updateObstacles(self.obsList)

				#Morph the obstacles
				self.map.updateMorph();
				dliteimage = cv2.resize(self.map.getImage(),(newWidth,newHeight))
				cv2.imwrite('AGVCmap2.bmp', dliteimage)
				imageMap.loadFile("AGVCmap2.bmp")
				mapper.initalize(imageMap,robot)
				moveGrid = imageMap.convertToGrid().copy()
				
			testvar = testvar + 1

			moveId = moveId+1
			print moveId
			if path.pathIsBroken(mapper.grid) :
				path.restart()
				print "The path is broken"
				#  dstar2.dstar(mapper, robot, goal, path)

				dstar.dstar(mapper, robot, self.goal, path)
		 
			#dlite.dstar(robot,goal,path)
			 #  #  DstarLite.dstar(mapper, robot, goal, path)
			  #  astar.astar(mapper, robot, goal, path)
			pathNode=path.getNextMove()
			robot.x = pathNode.x
			robot.y = pathNode.y
			mapper.moveGrid[pathNode.x][pathNode.y]="1"
			#mapper.printMoveGrid()
			self.vehicle.x = pathNode.x
			self.vehicle.y = pathNode.y
			self.vehicle.addPosition(pathNode.x,pathNode.y)
			mapper.updateMap(robot)
			#raw_input("TEST")
			cv2.imshow('AGVC Map', self.map.getMap())
			cv2.imshow('AGVC Map Morphed', self.map.getImage())
			for i in range(len(self.vehicle.positions)):
				self.map.placeRobot(self.vehicle.positions[i][1]*height/newHeight,self.vehicle.positions[i][0]*width/newWidth,self.vehicle.radius)
			nPoints = len(self.vehicle.positions)
			points = np.array(self.vehicle.positions)*height/newHeight
			#points = np.random.rand(nPoints,2)*200
			xpoints = [p[0] for p in points]
			ypoints = [p[1] for p in points]

			xvals, yvals = self.bezier_curve(points, nTimes=1000)
			for i in range(len(xvals)):
				self.map.placeRobot(int(yvals[i]),int(xvals[i]),self.vehicle.radius*2)

			self.map.updateActObstacles(self.obsList)
        
			cv2.waitKey(0)
Exemplo n.º 6
0
    #    skel = cv2.bitwise_or(skel,temp)
    #    img = eroded.copy()
 
         
    #    zeros = size - cv2.countNonZero(img)
    #    if zeros==size:
    #        done = True
 
    #cv2.imshow("skel",skel)
    #D* Lite Method ---------------------------------------------
    newHeight = int(height*0.1)
    newWidth = int(width*0.1)
    dliteimage = cv2.resize(agvcmap.getImage(),(newWidth,newHeight))
    cv2.imwrite('AGVCmap2.bmp', dliteimage)
    robot = Robot(TEG.x,TEG.y,TEG.radius*2)
    imageMap = ImageReader()
    imageMap.loadFile("AGVCmap2.bmp")
    mapper.initalize(imageMap,robot)
    moveGrid = imageMap.convertToGrid().copy()

    ##goal = point(3,17)
    testdivider = 1
    goal = point(int(newHeight/testdivider*0.8),int(newWidth/testdivider*0.8))
    #cv2.waitKey(0)

    ##mapper.printMoveGrid()

    print "STARTIN LOOP"
    moveId=0
    Xlength = mapper.grid.shape[0]/testdivider
    Ylength = mapper.grid.shape[1]/testdivider
Exemplo n.º 7
0
import time
import numpy as np
from imageReader import ImageReader
from keras.preprocessing.image import ImageDataGenerator
from cnn import CNN

if __name__ == "__main__":
    imageReader = ImageReader()
    cnn = CNN(imageReader.nGesture)

    (X, y), (Xv, yv) = imageReader.readImages(make1d=False,
                                              validationRatio=0.08)
    print len(X), "training data"
    print len(Xv), "test data"

    imageGenerator = ImageDataGenerator()

    cnn.train_gen(imageGenerator.flow(X, y, batch_size=16), len(X), Xv, yv)

    trainAccuracy = cnn.test(X, y)
    print "Training Accuracy :", trainAccuracy, "%"
    valAccuracy = cnn.test(Xv, yv)
    print "Test Accuracy :", valAccuracy, "%"

    #imageGenerator = ImageDataGenerator()
    #data = imageGenerator.flow_from_directory(directory='cropp', target_size=(100,100), color_mode='grayscale')
    #test = imageGenerator.flow_from_directory(directory='ASLval', target_size=(100,100), color_mode='grayscale')

    #cnn.train_gen(data, test)

    #trainAccuracy = cnn.test_gen(data, 11296)
Exemplo n.º 8
0
    def calculatePath(self):
        height = self.map.height
        width = self.map.width
        newHeight = int(height * 0.1)
        newWidth = int(width * 0.1)
        dliteimage = cv2.resize(self.map.getImage(), (newWidth, newHeight))
        cv2.imwrite('AGVCmap2.bmp', dliteimage)
        robot = Robot(self.vehicle.x, self.vehicle.y, self.vehicle.radius * 2)
        imageMap = ImageReader()
        imageMap.loadFile("AGVCmap2.bmp")
        mapper.initalize(imageMap, robot)
        moveGrid = imageMap.convertToGrid().copy()

        ##goal = point(3,17)
        testdivider = 1
        self.goal = point(int(newHeight / testdivider * 0.8),
                          int(newWidth / testdivider * 0.8))
        #cv2.waitKey(0)

        ##mapper.printMoveGrid()

        print "STARTIN LOOP"
        moveId = 0
        Xlength = mapper.grid.shape[0] / testdivider
        Ylength = mapper.grid.shape[1] / testdivider
        #dstar = dstar3.DStar(Xlength,Ylength,goal)
        dstar = dlite.Dlite(Xlength, Ylength, self.goal, robot)
        print "Entering Loop"
        testvar = 0

        #for i in range(10):
        while (robot.y != self.goal.y or robot.x != self.goal.x):
            if testvar % 2 == 0:
                newObs = obstacle.Obstacle(random.randint(0, height),
                                           random.randint(0, width), 40)
                self.map.placeObstacle(newObs, 3)
                self.obsList.append(newObs)
                #Place obstacles on map
                self.map.updateObstacles(self.obsList)

                #Morph the obstacles
                self.map.updateMorph()
                dliteimage = cv2.resize(self.map.getImage(),
                                        (newWidth, newHeight))
                cv2.imwrite('AGVCmap2.bmp', dliteimage)
                imageMap.loadFile("AGVCmap2.bmp")
                mapper.initalize(imageMap, robot)
                moveGrid = imageMap.convertToGrid().copy()

            testvar = testvar + 1

            moveId = moveId + 1
            print moveId
            if path.pathIsBroken(mapper.grid):
                path.restart()
                print "The path is broken"
                #  dstar2.dstar(mapper, robot, goal, path)

                dstar.dstar(mapper, robot, self.goal, path)

            #dlite.dstar(robot,goal,path)
            #  #  DstarLite.dstar(mapper, robot, goal, path)
            #  astar.astar(mapper, robot, goal, path)
            pathNode = path.getNextMove()
            robot.x = pathNode.x
            robot.y = pathNode.y
            mapper.moveGrid[pathNode.x][pathNode.y] = "1"
            #mapper.printMoveGrid()
            self.vehicle.x = pathNode.x
            self.vehicle.y = pathNode.y
            self.vehicle.addPosition(pathNode.x, pathNode.y)
            mapper.updateMap(robot)
            #raw_input("TEST")
            cv2.imshow('AGVC Map', self.map.getMap())
            cv2.imshow('AGVC Map Morphed', self.map.getImage())
            for i in range(len(self.vehicle.positions)):
                self.map.placeRobot(
                    self.vehicle.positions[i][1] * height / newHeight,
                    self.vehicle.positions[i][0] * width / newWidth,
                    self.vehicle.radius)
            nPoints = len(self.vehicle.positions)
            points = np.array(self.vehicle.positions) * height / newHeight
            #points = np.random.rand(nPoints,2)*200
            xpoints = [p[0] for p in points]
            ypoints = [p[1] for p in points]

            xvals, yvals = self.bezier_curve(points, nTimes=1000)
            for i in range(len(xvals)):
                self.map.placeRobot(int(yvals[i]), int(xvals[i]),
                                    self.vehicle.radius * 2)

            self.map.updateActObstacles(self.obsList)

            cv2.waitKey(0)
Exemplo n.º 9
0
import path
import astar
#import dstar
#import dstar2
#import dstar3
import dlite
#import DstarLite


'''
config = ConfigParser.SafeConfigParser()
config.read("robot.ini")
'''
#robot = Robot(17,4,44)
robot = Robot(3,17,5)
imageMap = ImageReader()
imageMap.loadFile("../map.bmp")
mapper.initalize(imageMap,robot)
moveGrid = imageMap.convertToGrid().copy()

#goal = point(3,17)
goal = point(17,4)

mapper.printMoveGrid()

print "STARTIN LOOP"
moveId=0
Xlength = mapper.grid.shape[0]
Ylength = mapper.grid.shape[1]
#dstar = dstar3.DStar(Xlength,Ylength,goal)
dstar = dlite.Dlite(Xlength,Ylength,goal,robot)