Changeset - 5f42b982809c
[Not reviewed]
default
0 3 0
Laman - 6 years ago 2019-05-24 11:31:52

deferred data preprocessing saving space
3 files changed with 6 insertions and 6 deletions:
0 comments (0 inline, 0 general)
exp/kerokero/prepare_data.py
Show inline comments
 
@@ -34,13 +34,13 @@ class Sample:
 
		rot=getRotation()
 
		mir=getMirroring()
 
		for mi in [t1,mir,proj,rot]:
 
			m=np.matmul(mi,m)
 
		m=np.matmul(self._computeCrop(m),m)
 
		img=cv.warpPerspective(self.img,m,(self.SIDE,self.SIDE))
 
		img=np.float32(img)/128-1
 
		img=np.uint8(img)
 
		grid=Corners(c.transform(m) for c in self.grid)
 
		grid=list(map(lambda p: list(2*p/self.SIDE-EPoint(1,1)), grid))
 
		return (img,grid)
 

	
 
	def _getCenter(self):
 
		(a,b,c,d)=self.grid
 
@@ -105,14 +105,14 @@ def loadDataset(root):
 
	keys=list(range(n))
 
	random.shuffle(keys)
 
	images=[images[k] for k in keys]
 
	labels=[labels[k] for k in keys]
 
	m=int(n*trainRatio)
 
	return (
 
		(np.float32(images[:m]),np.float32(labels[:m])),
 
		(np.float32(images[m:]),np.float32(labels[m:]))
 
		(np.uint8(images[:m]),np.float32(labels[:m])),
 
		(np.uint8(images[m:]),np.float32(labels[m:]))
 
	)
 

	
 

	
 
def show(img,filename="x"):
 
	cv.imshow(filename,img)
 
	cv.waitKey(0)
exp/kerokero/test.py
Show inline comments
 
@@ -21,13 +21,13 @@ args=parser.parse_args()
 

	
 
model=load_model(args.model)
 
model.summary()
 

	
 
log.info("loading data...")
 
with np.load(args.data) as data:
 
	testImages=data["testImages"].reshape((-1,224,224,1))
 
	testImages=(np.float32(data["testImages"])/128-1).reshape((-1,224,224,1))
 
	testLabels=data["testLabels"].reshape((-1,4,2))
 
log.info("done")
 

	
 
log.info(model.evaluate(testImages,testLabels))
 

	
 
for img in testImages:
exp/kerokero/train.py
Show inline comments
 
@@ -76,15 +76,15 @@ def createCNN():
 
model=createCNN()
 
if args.load_model:
 
	model=load_model(args.load_model)
 

	
 
log.info("loading data...")
 
with np.load(args.data) as data:
 
	trainImages=data["trainImages"].reshape((-1,224,224,1))
 
	trainImages=(np.float32(data["trainImages"])/128-1).reshape((-1,224,224,1))
 
	trainLabels=data["trainLabels"].reshape((-1,4,2))
 
	testImages=data["testImages"].reshape((-1,224,224,1))
 
	testImages=(np.float32(data["testImages"])/128-1).reshape((-1,224,224,1))
 
	testLabels=data["testLabels"].reshape((-1,4,2))
 
log.info("done")
 

	
 
n=len(trainImages)
 
k=round(n*0.9)
 
n_=n-k
0 comments (0 inline, 0 general)