Created
July 25, 2016 21:25
-
-
Save anonymous/6e0e125bddcbb594c1a79c3a28d5d8af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pybrain.tools.shortcuts import buildNetwork | |
from pybrain.tools.xml import NetworkWriter | |
from pybrain.tools.xml import NetworkReader | |
from pybrain.datasets import SupervisedDataSet | |
from pybrain.supervised.trainers import BackpropTrainer | |
import cv2 | |
import numpy as np | |
net = buildNetwork(921600, 12, 921600) | |
ds = SupervisedDataSet(921600, 921600) | |
trainer = BackpropTrainer(net, ds) | |
imageArray = [] | |
for it in range(1,51): | |
imageArray.append(str(it) + '.jpg') | |
print imageArray | |
for image in imageArray: | |
outputImage = image | |
resultImage = 'result.jpg' | |
inputImage = 'input.jpg' | |
otherImage = 'other.jpg' | |
#LOAD IMAGE FILES | |
imgIn = cv2.imread(inputImage) | |
imgOut = cv2.imread(outputImage) | |
imgResult = cv2.imread(resultImage) | |
imgOther = cv2.imread(otherImage) | |
#BIT ARRAYS FOR EACH IMAGE | |
imagebitsInput = [] | |
imagebitsOutput = [] | |
imagebitsOther = [] | |
#CONVERT INPUT TO GRAYSCALE | |
gray_in = cv2.cvtColor(imgIn, cv2.COLOR_BGR2GRAY) | |
gray_out = cv2.cvtColor(imgOut, cv2.COLOR_BGR2GRAY) | |
gray_other = cv2.cvtColor(imgOther, cv2.COLOR_BGR2GRAY) | |
#FILL BIT ARRAYS | |
for row in gray_in: | |
for pixel in row: | |
imagebitsInput.append(pixel) | |
for row in gray_out: | |
for pixel in row: | |
imagebitsOutput.append(pixel) | |
for row in gray_other: | |
for pixel in row: | |
imagebitsOther.append(pixel) | |
ds.addSample(imagebitsInput, imagebitsOutput) | |
trainer.trainEpochs(epochs=4) | |
imagebitsFinal = net.activate(imagebitsOther) | |
for it in range(720): #y | |
for it2 in range(1280): #x | |
imgResult[it][it2] = imagebitsFinal[(1280*it)+it2] | |
cv2.imwrite('result.jpg', imgResult) | |
print 'Images in training set: ' | |
print len(ds) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment