@Override public void initialize(Map<String, Param> params) throws TikaConfigException { //STEP 1: resolve weights file, download if necessary modelWeightsPath = mayBeDownloadFile(modelWeightsPath); //STEP 2: Load labels map try (InputStream stream = retrieveResource(mayBeDownloadFile(labelFile))) { this.labelMap = loadClassIndex(stream); } catch (IOException | ParseException e) { LOG.error("Could not load labels map", e); return; } //STEP 3: initialize the graph try { this.imageLoader = new NativeImageLoader(imgHeight, imgWidth, imgChannels); LOG.info("Going to load Inception network..."); long st = System.currentTimeMillis(); KerasModelBuilder builder = new KerasModel().modelBuilder().modelHdf5Filename(modelWeightsPath) .enforceTrainingConfig(false); builder.inputShape(new int[]{imgHeight, imgWidth, 3}); KerasModel model = builder.buildModel(); this.graph = model.getComputationGraph(); long time = System.currentTimeMillis() - st; LOG.info("Loaded the Inception model. Time taken={}ms", time); } catch (IOException | InvalidKerasConfigurationException | UnsupportedKerasConfigurationException e) { throw new TikaConfigException(e.getMessage(), e); } }
public ImageWritable transformFileUriToInput(URI uri) throws IOException { NativeImageLoader imageLoader = new NativeImageLoader(); ImageWritable img = imageLoader.asWritable(new File(uri)); return img; }
public INDArray executeArray(ImageWritable image) throws IOException { Random random = null; if (seed != 0) { random = new Random(seed); } ImageWritable currentImage = image; for (ImageTransform transform : transformList) { currentImage = transform.transform(currentImage, random); } NativeImageLoader imageLoader = new NativeImageLoader(); return imageLoader.asMatrix(currentImage); }
@Override public void setConf(Configuration conf) { super.setConf(conf); converter = new OpenCVFrameConverter.ToMat(); imageLoader = new NativeImageLoader(rows, cols); }
@Override public List<Writable> record(URI uri, DataInputStream dataInputStream) throws IOException { invokeListeners(uri); if (imageLoader == null) { imageLoader = new NativeImageLoader(height, width, channels, imageTransform); } INDArray row = imageLoader.asMatrix(dataInputStream); List<Writable> ret = RecordConverter.toRecord(row); if (appendLabel) ret.add(new IntWritable(labels.indexOf(getLabel(uri.getPath())))); return ret; }
.restoreMultiLayerNetworkAndNormalizer(new File("model/AlexNet.zip"), false); NativeImageLoader imageLoader = new NativeImageLoader(256, 256, 3);
@Override public void initialize(InputSplit split) throws IOException { if (imageLoader == null) { imageLoader = new NativeImageLoader(height, width, channels, imageTransform);
private INDArray prepareImage(Mat file, int width, int height) throws IOException { NativeImageLoader loader = new NativeImageLoader(height, width, 3); ImagePreProcessingScaler imagePreProcessingScaler = new ImagePreProcessingScaler(0, 1); INDArray indArray = loader.asMatrix(file); imagePreProcessingScaler.transform(indArray); return indArray; }
@Override public void initialize(InputSplit split) throws IOException, InterruptedException { if (imageLoader == null) { imageLoader = new NativeImageLoader(height, width);
@Override public List<Writable> next(int num) { if (imageLoader == null) { imageLoader = new NativeImageLoader(height, width, channels, imageTransform);
@Override public void initialize(Configuration conf, InputSplit split) throws IOException, InterruptedException { this.conf = conf; this.appendLabel = conf.getBoolean(APPEND_LABEL, false); this.height = conf.getInt(HEIGHT, height); this.width = conf.getInt(WIDTH, width); if ("imageio".equals(conf.get(IMAGE_LOADER))) { this.imageLoader = new ImageLoader(height, width); } else { this.imageLoader = new NativeImageLoader(height, width); } initialize(split); }
public static void init() throws IOException { String modelPath = Properties.classifierModelPath(); labels = Properties.classifierLabels(); int[] format = Properties.classifierInputFormat(); loader = new NativeImageLoader(format[0], format[1], format[2]); model = ModelSerializer.restoreComputationGraph(modelPath); model.init(); }
NativeImageLoader imageLoader = new NativeImageLoader(height, width, channel);
@Override public void initialize(Configuration conf, InputSplit split) throws IOException, InterruptedException { this.appendLabel = conf.getBoolean(APPEND_LABEL, false); this.labels = new ArrayList<>(conf.getStringCollection(LABELS)); this.height = conf.getInt(HEIGHT, height); this.width = conf.getInt(WIDTH, width); this.channels = conf.getInt(CHANNELS, channels); this.cropImage = conf.getBoolean(CROP_IMAGE, cropImage); if ("imageio".equals(conf.get(IMAGE_LOADER))) { this.imageLoader = new ImageLoader(height, width, channels, cropImage); } else { this.imageLoader = new NativeImageLoader(height, width, channels, imageTransform); } this.conf = conf; initialize(split); }
NativeImageLoader imageLoader = new NativeImageLoader(); CanvasFrame frame = new CanvasFrame("RedBloodCellDetection"); OpenCVFrameConverter.ToMat converter = new OpenCVFrameConverter.ToMat();