gpt4 book ai didi

org.deeplearning4j.zoo.ZooModel.initPretrained()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-15 19:17:31 25 4
gpt4 key购买 nike

本文整理了Java中org.deeplearning4j.zoo.ZooModel.initPretrained()方法的一些代码示例,展示了ZooModel.initPretrained()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZooModel.initPretrained()方法的具体详情如下:
包路径:org.deeplearning4j.zoo.ZooModel
类名称:ZooModel
方法名:initPretrained

ZooModel.initPretrained介绍

[英]By default, will return a pretrained ImageNet if available.
[中]默认情况下,将返回预训练的ImageNet(如果可用)。

代码示例

代码示例来源:origin: deeplearning4j/dl4j-examples

public static void main(String [] args) throws UnsupportedKerasConfigurationException, IOException, InvalidKerasConfigurationException {
  //import org.deeplearning4j.transferlearning.vgg16 and print summary
  LOGGER.info("\n\nLoading org.deeplearning4j.transferlearning.vgg16...\n\n");
  ZooModel zooModel = VGG16.builder().build();
  ComputationGraph vgg16 = (ComputationGraph) zooModel.initPretrained();
  LOGGER.info(vgg16.summary());
  //use the TransferLearningHelper to freeze the specified vertices and below
  //NOTE: This is done in place! Pass in a cloned version of the model if you would prefer to not do this in place
  TransferLearningHelper transferLearningHelper = new TransferLearningHelper(vgg16, featurizeExtractionLayer);
  LOGGER.info(vgg16.summary());
  FlowerDataSetIterator.setup(batchSize,trainPerc);
  DataSetIterator trainIter = FlowerDataSetIterator.trainIterator();
  DataSetIterator testIter = FlowerDataSetIterator.testIterator();
  int trainDataSaved = 0;
  while(trainIter.hasNext()) {
    DataSet currentFeaturized = transferLearningHelper.featurize(trainIter.next());
    saveToDisk(currentFeaturized,trainDataSaved,true);
    trainDataSaved++;
  }
  int testDataSaved = 0;
  while(testIter.hasNext()) {
    DataSet currentFeaturized = transferLearningHelper.featurize(testIter.next());
    saveToDisk(currentFeaturized,testDataSaved,false);
    testDataSaved++;
  }
  LOGGER.info("Finished pre saving featurized test and train data");
}

代码示例来源:origin: deeplearning4j/dl4j-examples

public static void main(String [] args) throws UnsupportedKerasConfigurationException, IOException, InvalidKerasConfigurationException {
  //import org.deeplearning4j.transferlearning.vgg16 and print summary
  LOGGER.info("\n\nLoading org.deeplearning4j.transferlearning.vgg16...\n\n");
  ZooModel zooModel = VGG16.builder().build();
  ComputationGraph vgg16 = (ComputationGraph) zooModel.initPretrained();
  LOGGER.info(vgg16.summary());
  //use the TransferLearningHelper to freeze the specified vertices and below
  //NOTE: This is done in place! Pass in a cloned version of the model if you would prefer to not do this in place
  TransferLearningHelper transferLearningHelper = new TransferLearningHelper(vgg16, featurizeExtractionLayer);
  LOGGER.info(vgg16.summary());
  FlowerDataSetIterator.setup(batchSize,trainPerc);
  DataSetIterator trainIter = FlowerDataSetIterator.trainIterator();
  DataSetIterator testIter = FlowerDataSetIterator.testIterator();
  int trainDataSaved = 0;
  while(trainIter.hasNext()) {
    DataSet currentFeaturized = transferLearningHelper.featurize(trainIter.next());
    saveToDisk(currentFeaturized,trainDataSaved,true);
    trainDataSaved++;
  }
  int testDataSaved = 0;
  while(testIter.hasNext()) {
    DataSet currentFeaturized = transferLearningHelper.featurize(testIter.next());
    saveToDisk(currentFeaturized,testDataSaved,false);
    testDataSaved++;
  }
  LOGGER.info("Finished pre saving featurized test and train data");
}

代码示例来源:origin: deeplearning4j/dl4j-examples

ComputationGraph vgg16 = (ComputationGraph) zooModel.initPretrained();
log.info(vgg16.summary());

代码示例来源:origin: deeplearning4j/dl4j-examples

ComputationGraph vgg16 = (ComputationGraph) zooModel.initPretrained();
log.info(vgg16.summary());

代码示例来源:origin: apache/tika

@Override
public void initialize(Map<String, Param> params) throws TikaConfigException {
  try {
    if (serialize) {
      if (cacheDir.exists()) {
        model = ModelSerializer.restoreComputationGraph(cacheDir);
        LOG.info("Preprocessed Model Loaded from {}", cacheDir);
      } else {
        LOG.warn("Preprocessed Model doesn't exist at {}", cacheDir);
        cacheDir.getParentFile().mkdirs();
        ZooModel zooModel = VGG16.builder().build();
        model = (ComputationGraph)zooModel.initPretrained(PretrainedType.IMAGENET);
        LOG.info("Saving the Loaded model for future use. Saved models are more optimised to consume less resources.");
        ModelSerializer.writeModel(model, cacheDir, true);
      }
    } else {
      LOG.info("Weight graph model loaded via dl4j Helper functions");
      ZooModel zooModel = VGG16.builder().build();
      model = (ComputationGraph)zooModel.initPretrained(PretrainedType.IMAGENET);
    }
    imageNetLabels = new ImageNetLabels();
    available = true;
  } catch (Exception e) {
    available = false;
    LOG.warn(e.getMessage(), e);
    throw new TikaConfigException(e.getMessage(), e);
  }
}

代码示例来源:origin: org.deeplearning4j/deeplearning4j-zoo

/**
 * By default, will return a pretrained ImageNet if available.
 *
 * @return
 * @throws IOException
 */
public Model initPretrained() throws IOException {
  return initPretrained(PretrainedType.IMAGENET);
}

代码示例来源:origin: sjsdfg/dl4j-tutorials

private ComputationGraph loadModel() throws IOException {
  ZooModel zooModel = VGG16.builder().build();
  ComputationGraph vgg16 = (ComputationGraph) zooModel.initPretrained(PretrainedType.IMAGENET);
  vgg16.initGradientsView();
  log.info(vgg16.summary());
  return vgg16;
}

代码示例来源:origin: sjsdfg/dl4j-tutorials

ComputationGraph vgg16 = (ComputationGraph) zooModel.initPretrained();

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com