def batchProcessor(self, pathsX, Y): X = [] for filename in pathsX: img = ImageOps.readImage(os.path.join(os.path.join(self.__path, self.__imageDir), filename)) img = ImageOps.resizeImage(img, self.imageSize, self.imageSize) img = img / 255 X.append(img) return np.array(X), np.array(Y)
def imageOps(self): if self.isLoaded: dialog = ImageOps(self.image) if dialog.isChanged(): self.image = dialog.getAfterQImage() self.pixmap = QPixmap.fromImage(self.image) self.internalPixmap.setPixmap(self.pixmap) self.scene.update() self.graphicsView.update() QApplication.processEvents()
def batchProcessor(self, paths): X = [] Y = [] for path in paths: temp = [] path = os.path.join(path, 'cat_') for i in range(5): temp.append(ImageOps.readImage(path + str(i) + '.jpg') / 255) Y.append(ImageOps.readImage(path + 'result.jpg') / 255) X.append(np.array(temp)) return np.array(X), np.array(Y)
def batchProcessor(self, filenames): X = [] Y = [] for filename in filenames: img = ImageOps.readImage(os.path.join(self.imagesDir, filename + '.jpg')) img = ImageOps.resizeImage(img, self.imageSize, self.imageSize) if len(img.shape) == 2: img = np.pad(img.reshape((self.imageSize, self.imageSize, 1)), [(0, 0), (0, 0), (0, 2)], mode='constant', constant_values=0) X.append(img) Y.append(h5py.File(os.path.join(self.annotationsDir, filename + '.mat'), 'r')) return np.array(X), np.array(Y)
def batchProcessor(self, pathX, Y): resultX = [] resultY = [] for i in range(len(pathX)): try: x = ImageOps.readImage(pathX[i]) x = ImageOps.resizeImageWithAspectRatio(x, self.imageSize) x = np.reshape(x, (-1)) if x is None or len(x) != self.imageSize * self.imageSize * 3: raise Exception resultX.append(np.array(x)/255.0) resultY.append(Y[i]) except: print("file removed:", pathX[i]) #os.remove(pathX[i]) return np.concatenate(resultX, axis=0).reshape((-1, self.imageSize, self.imageSize, 3)), np.array( resultY).reshape((-1))
import sys from Model import Vgg16 from Trainer import Trainer import numpy as np from ImageOps import ImageOps imageOps = ImageOps() batchsize = 32 imageSize = 64 model = Vgg16() model.noOfClasses = 2 model.hiddenUnits = 2048 model.imageShape = [imageSize, imageSize, 3] model.addMetrics('Accuracy') model.convActivation = "relu" model.fcActivation = "leakyrelu" model.regularizationCoefficient = 0.005 model.regularizationType = "l2" model.build() trainer = Trainer(model) trainer.batchSize = 32 trainer.workingDir = "vggDogCat" img = imageOps.readImage(["test1.jpg", "test2.jpg"]) img = imageOps.resizeImageWithAspectRatio(img, imageSize) img = np.array(img).reshape([-1, imageSize, imageSize, 3]) print(img.shape) test = {"x": img}
import sys sys.path.insert(0, '../') from DataQueue import DataQueue from Model import Vgg16 from Trainer import Trainer import numpy as np from Datasets import ClassificationImageGenerator from ImageOps import ImageOps imageOps = ImageOps() batchsize = 32 imageSize = 64 trainGen = ClassificationImageGenerator( '/media/batman/ent/datasets/kagglecatsanddogs_3367a/images', batchsize, imageSize=64) testGen = ClassificationImageGenerator( '/media/batman/ent/datasets/kagglecatsanddogs_3367a/PetImages', batchsize, imageSize=64, batchType="sequential") testGen.init() test = {'x': [], 'y': []} for _ in range(20): x, y = testGen.batchProcessor(*tuple(testGen.batchGenerator())) test['x'].append(np.array(x)) test['y'].append(np.array(y)) test['x'] = np.concatenate(test['x'], axis=0)