GVKun编程网logo

无法在 Google AI Platform 上部署 pytorch 文本分类器模型,错误:无法从“prediction_server_beta.py”中获取

19

对于无法在GoogleAIPlatform上部署pytorch文本分类器模型,错误:无法从“prediction_server_beta.py”中获取感兴趣的读者,本文将提供您所需要的所有信息,并且为

对于无法在 Google AI Platform 上部署 pytorch 文本分类器模型,错误:无法从“prediction_server_beta.py”中获取 感兴趣的读者,本文将提供您所需要的所有信息,并且为您提供关于android – 错误:资源整数/ google_play_services_version(又名app:integer / google_play_services_version)未找到、Angular 2 AOT不起作用.为什么“platformBrowser().bootstrapModuleFactory”使用附加前缀“/ src / linker / ng_module_factory”拉取链接?、Angular 6 Server Side Errror:找不到模块:错误:无法解析’./dist/server/main.bundle’、angular – ionic 4 google-maps 5 beta“TypeError:无法读取属性’BaseClass’的null”的宝贵知识。

本文目录一览:

无法在 Google AI Platform 上部署 pytorch 文本分类器模型,错误:无法从“prediction_server_beta.py”中获取 <module 'main' 上的属性>

无法在 Google AI Platform 上部署 pytorch 文本分类器模型,错误:无法从“prediction_server_beta.py”中获取

如何解决无法在 Google AI Platform 上部署 pytorch 文本分类器模型,错误:无法从“prediction_server_beta.py”中获取 <module ''main'' 上的属性>?

我遵循了这个 article,尝试在 Google AI 平台上部署 PyTorch 文本分类器,得到以下错误。

创建版本失败。错误模型检测到错误:“加载失败 模型:加载模型时出现意外错误:无法获取属性 ma​​in'' 上的 ''TextPreprocessor'' 来自 ''prediction_server_beta.py''>(错误代码:0)”

我通过GUI部署模型,这里是设置

!gcloud ai-platform versions create {v17} \
    --model {pytorch_text_classfier} \
    --origin=gs://pytorch_text_classfier_package \
    --python-version=3.7 \
    --runtime-version={1.15} \
    --framework ={"Custom prediction routine (BETA)"} \
    --package-uris=gs://pytorch_model_distribution_package_v3/my_package-1.7.tar.gz\
    --machine-type=mls1-c4-m4 \
    --prediction-class=model_prediction.CustomModelPrediction

我向存储桶上传了五个文件,model_prediction.py、preprocess.py、processor_state.pkl、setup.py、torch_model.py、torch_saved_model.pt。 tar.gz 文件在另一个存储桶中。

有没有人知道如何解决这个错误?

下面是model_prediction.py、preprocess.py、torch_model.py、setup.py代码。

model_prediction.py

import os
import pickle
import numpy as np
import torch
import torch.nn as nn
from torch.autograd import Variable
from tensorflow.python.keras.preprocessing import sequence
from tensorflow.keras.preprocessing import text
from preprocess import TextPreprocessor
from torch_model import TorchTextClassifier

device = torch.device(''cuda:0'' if torch.cuda.is_available() else ''cpu'')


class CustomModelPrediction(object):
 def __init__(self,model,processor):
   self._model = model
   self._processor = processor

 def _postprocess(self,predictions):
   labels = [''no confusion'',''confusion'']
   label_indexes = [np.argmax(prediction) for prediction in predictions.detach().numpy()]
   return [labels[label_index] for label_index in label_indexes]

 def predict(self,instances,**kwargs):
   preprocessed_data = self._processor.transform(instances)
   predictions =  self._model(Variable(torch.Tensor(preprocessed_data).long()))
   labels = self._postprocess(predictions)
   return labels

 @classmethod
 def from_path(cls,model_dir):

  import torch
  import torch_model

  state_dict = torch.load(os.path.join(model_dir,''torch_saved_model.pt''),map_location= device)
  print(f''Model loaded from <== {model_dir}'')
  model = TorchTextClassifier().to(device)
  model.load_state_dict(state_dict[''model_state_dict''])
  model.eval()
  print(''set to eval mode'')  
  with open(os.path.join(model_dir,''processor_state.pkl''),''rb'') as f:
      processor = pickle.load(f)
  print(''loaded processor'')
  return cls(model,processor)

proprocess.py

from tensorflow.python.keras.preprocessing import sequence
from tensorflow.keras.preprocessing import text


class TextPreprocessor(object):
 def __init__(self,vocab_size,max_sequence_length):
   self._vocab_size = vocab_size
   self._max_sequence_length = max_sequence_length
   self._tokenizer = None

 def fit(self,text_list):       
   # Create vocabulary from input corpus.
   tokenizer = text.Tokenizer(num_words=self._vocab_size)
   tokenizer.fit_on_texts(text_list)
   self._tokenizer = tokenizer

 def transform(self,text_list):       
   # Transform text to sequence of integers
   text_sequence = self._tokenizer.texts_to_sequences(text_list)

   # Fix sequence length to max value. Sequences shorter than the length are
   # padded in the beginning and sequences longer are truncated
   # at the beginning.
   padded_text_sequence = sequence.pad_sequences(text_sequence,maxlen=self._max_sequence_length,padding=''post'')
   return padded_text_sequence

setup.py

from setuptools import setup

setup(
 name="my_package",version="1.6",include_package_data=True,scripts=["preprocess.py","model_prediction.py","torch_model.py"],install_requires=[''torch @ https://download.pytorch.org/whl/cpu/torch-1.7.0%2Bcpu-cp37-cp37m-linux_x86_64.whl'']
)

torch_model.py

import torch
import torch.nn as nn
from torch.autograd import Variable
from tensorflow.python.keras.preprocessing import sequence
from tensorflow.keras.preprocessing import text

text_field_vocab_length = 15832  # this is set based on training data


class TorchTextClassifier(nn.Module):

    def __init__(self,dimension=128):
        super(TorchTextClassifier,self).__init__()

        self.embedding = nn.Embedding(text_field_vocab_length,300)
        self.dimension = dimension
        self.lstm = nn.LSTM(input_size=300,hidden_size=dimension,num_layers=1,batch_first=True,bidirectional=True)
        self.drop = nn.Dropout(p=0.5)

        self.fc = nn.Linear(2*dimension,2)

    def forward(self,text,text_len):

        text_emb = self.embedding(text)

        packed_input = pack_padded_sequence(text_emb,text_len,enforce_sorted=False)
        packed_output,_ = self.lstm(packed_input)
        output,_ = pad_packed_sequence(packed_output,batch_first=True)

        out_forward = output[range(len(output)),text_len - 1,:self.dimension]
        out_reverse = output[:,self.dimension:]
        out_reduced = torch.cat((out_forward,out_reverse),1)
        text_fea = self.drop(out_reduced)

        text_fea = self.fc(text_fea)
        text_fea = torch.squeeze(text_fea,1)
        text_out = torch.softmax(text_fea,dim=-1)

        return text_out

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

android – 错误:资源整数/ google_play_services_version(又名app:integer / google_play_services_version)未找到

android – 错误:资源整数/ google_play_services_version(又名app:integer / google_play_services_version)未找到

编译或运行项目时出错.我想计算一下我旅行的距离.我的Android工作室版本是Android Studio 3.1.4

当我在build.gradle(Model:app)中添加以下库时,将发生此错误.

implementation 'com.google.android.gms:play-services-location:12.0.1'

错误进入以下文件:

…\app\build\intermediates\manifests\full\debug\AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="shravan.measuredistance.app"
android:targetSandBoxVersion="2"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="15"
    android:targetSdkVersion="26" />

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />

<application
    android:name="android.support.multidex.MultiDexApplication"
    android:allowBackup="true"
    android:debuggable="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:testOnly="true"
    android:theme="@style/AppTheme" >
    <Meta-data
        android:name="aia-compat-api-min-version"
        android:value="1" />
    <Meta-data
        android:name="android.support.VERSION"
        android:value="26.1.0" />
    <Meta-data
        android:name="android.arch.lifecycle.VERSION"
        android:value="27.0.0-SNAPSHOT" />

    <activity
        android:name="shravan.measuredistance.distance.MainActivity"
        android:splitName="distance" >
        <intent-filter android:order="1" >
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.broWSABLE" />
            <category android:name="android.intent.category.DEFAULT" />

            <data
                android:host="www.atjoin.in"
                android:pathPattern="/.*"
                android:scheme="https" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <service
        android:name="shravan.measuredistance.distance.LocationService"
        android:splitName="distance" />

    <activity
        android:name="com.google.android.gms.common.api.GoogleApiActivity"
        android:exported="false"
        android:splitName="distance"
        android:theme="@android:style/Theme.Translucent.NoTitleBar" />

    <Meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
</application>

请给我这个建议.谢谢.

解决方法:

我遇到过同样的问题.在应用程序gradle文件中添加Play服务库.
实现’com.google.android.gms:play-services:9.2.1’或更高版本.然后重建.

Angular 2 AOT不起作用.为什么“platformBrowser().bootstrapModuleFactory”使用附加前缀“/ src / linker / ng_module_factory”拉取链接?

Angular 2 AOT不起作用.为什么“platformBrowser().bootstrapModuleFactory”使用附加前缀“/ src / linker / ng_module_factory”拉取链接?

当我使用JIT运行我的Angular 2应用程序时,一切正常.
但是在我切换到AOT后,我的应用程序开始拉动带有附加前缀的链接(“/ src / linker / ng_module_factory”),例如:

JIT拉:http:// localhost:8080/node_modules/@angular/core/bundles/core.umd.js

AOT拉:http:// localhost:8080/node_modules/@angular/core/bundles/core.umd.js/src/linker/ng_module_factory
postfix / src / linker / ng_module_factory来自哪里?

关于app.我正在使用Java 8 Spring 4.3.2.RELEASE Angular 2 Tomcat 9.0.0.M6.

src
--main
----webapp
------resources
--------app
----------app.component.css
----------app.component.ts
----------app.module.ts
----------main.ts
--------index.html
--------package.json
--------systemjs.config.js
--------tsconfig.json
--------typings.json
------WEB-INF
--------dispatcher-servlet.xml
--------web.xml

的package.json

{
  "name": "my-app","version": "1.0.0","scripts": {
    "postinstall": "typings install"
  },"license": "MIT","dependencies": {
    "@angular/common":  "2.0.0","@angular/compiler":  "2.0.0","@angular/core":  "2.0.0","@angular/platform-browser":  "2.0.0","@angular/platform-browser-dynamic":  "2.0.0","systemjs": "0.19.27","core-js": "^2.4.1","reflect-Metadata": "^0.1.3","rxjs": "5.0.0-beta.12","zone.js": "^0.6.23","bootstrap": "^3.3.6"
  },"devDependencies": {
    "typescript": "^2.0.2","typings": "^1.0.4"
  },"repository": {}
}

的index.html

<!DOCTYPE html>
<html>
<head>
  <base href="/">
  <title>MyApp</title>
  <Meta charset="UTF-8">
  <Meta name="viewport" content="width=device-width,initial-scale=1">

  <script src="node_modules/core-js/client/shim.min.js"></script>
  <script src="node_modules/zone.js/dist/zone.js"></script>
  <script src="node_modules/reflect-Metadata/Reflect.js"></script>
  <script src="node_modules/systemjs/dist/system.src.js"></script>

  <script src="systemjs.config.js"></script>
  <script>
      System.import('app').catch(function(err){ console.error(err); });
    </script>
</head>

<body>
<my-app>Loading...</my-app>
</body>
</html>

systemjs.config.js

(function (global) {
  System.config({
    paths: {
      'npm:': 'node_modules/'
    },map: {
      app: 'app','@angular/core': 'npm:@angular/core/bundles/core.umd.js','@angular/common': 'npm:@angular/common/bundles/common.umd.js','@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js','@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js','@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js','rxjs': 'npm:rxjs',},packages: {
      app: {
        main: './main.js',defaultExtension: 'js'
      },rxjs: {
        defaultExtension: 'js'
      }
    }
  });
})(this);

tsconfig.json

{
  "compilerOptions": {
    "target": "es5","module": "commonjs","moduleResolution": "node","sourceMap": true,"emitDecoratorMetadata": true,"experimentalDecorators": true,"removeComments": false,"noImplicitAny": true,"suppressImplicitAnyIndexErrors": true
  }
}

typings.json

{
  "globalDependencies": {
    "core-js": "registry:dt/core-js#0.0.0+20160725163759"
  }
}

app.component.ts

import { Component } from '@angular/core';

@Component({
  selector: 'my-app',template: `
    <h1>{{title}}</h1>
  `,styleUrls: ['app.component.css']
})
export class AppComponent{
    title = 'Title';
}

app.module.ts

import { NgModule }      from '@angular/core';
import { browserModule } from '@angular/platform-browser';
import { AppComponent }  from './app.component';

@NgModule({
  imports: [
    browserModule
  ],declarations: [
    AppComponent
  ],bootstrap: [ AppComponent ]
})
export class AppModule {}

JIT配置
main.ts

import { platformbrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app.module';
platformbrowserDynamic().bootstrapModule(AppModule);

下一步是使用命令tsc进行编译,构建war和deploy.

AOT配置
main.ts

import { platformbrowser } from '@angular/platform-browser';
import { AppModuleNgFactory } from './app.module.ngfactory';
platformbrowser().bootstrapModuleFactory(AppModuleNgFactory);

下一步是安装编译器npm install @ angular / compiler-cli,使用命令’./ node_modules / .bin / ngc’进行编译,构建war和deploy.
在ngc命令后,我得到文件* .ngfactory.ts,* .ngfactory.js,* .Metadata.json,* .shim.ts,* .shim.js

解决方法

使用angular2-webpack-starter,不用担心

https://github.com/AngularClass/angular2-webpack-starter

Angular 6 Server Side Errror:找不到模块:错误:无法解析’./dist/server/main.bundle’

Angular 6 Server Side Errror:找不到模块:错误:无法解析’./dist/server/main.bundle’

我正在开发一个项目,将其更新为Angular 6.更新后,我在尝试运行服务器端渲染构建时遇到此错误
Module not found: Error: Can't resolve './dist/server/main.bundle'

我尝试使用https://angular.io/guide/universal并将我的代码与Angular Universal中的SSR文件相匹配.这对我不起作用.

似乎dist文件夹没有生成/ server文件夹,但正在创建/浏览器.我不确定为什么.

这是我的angular.json文件

{
 "$schema": "./node_modules/@angular/cli/lib/config/schema.json","version": 1,"newProjectRoot": "projects","projects": {
    "xilo": {
      "root": "","sourceRoot": "src","projectType": "application","architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser","options": {
            "outputPath": "dist/browser","index": "src/index.html","main": "src/main.ts","tsConfig": "src/tsconfig.app.json","polyfills": "src/polyfills.ts","assets": [
              "src/assets","src/favicon.ico"
            ],"styles": [
              "src/styles.css","node_modules/font-awesome/css/font-awesome.min.css"
            ],"scripts": [
              "node_modules/moment/min/moment.min.js"
            ]
          },"configurations": {
            "production": {
              "optimization": true,"outputHashing": "all","sourceMap": false,"extractCss": true,"namedChunks": false,"aot": true,"extractLicenses": true,"vendorChunk": false,"buildOptimizer": true,"fileReplacements": [
                {
                  "replace": "src/environments/environment.ts","with": "src/environments/environment.prod.ts"
                }
              ]
            }
          }
        },"serve": {
          "builder": "@angular-devkit/build-angular:dev-server","options": {
            "browserTarget": "xilo:build"
          },"configurations": {
            "production": {
              "browserTarget": "xilo:build:production"
            }
          }
        },"extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n","options": {
            "browserTarget": "xilo:build"
          }
        },"test": {
          "builder": "@angular-devkit/build-angular:karma","options": {
            "main": "src/test.ts","karmaConfig": "./karma.conf.js","tsConfig": "src/tsconfig.spec.json","scripts": [
              "node_modules/moment/min/moment.min.js"
            ],"src/favicon.ico"
            ]
          }
        },"lint": {
          "builder": "@angular-devkit/build-angular:tslint","options": {
            "tsConfig": [
              "src/tsconfig.app.json","src/tsconfig.spec.json"
            ],"exclude": [
              "**/node_modules/**"
            ]
          }
        },"server": {
          "builder": "@angular-devkit/build-angular:server","options": {
            "outputPath": "dist/server","main": "main.server.ts","tsConfig": "tsconfig.server.json"
          }
        }
      }
    },"xilo-e2e": {
      "root": "","sourceRoot": "e2e","architect": {
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor","options": {
            "protractorConfig": "./protractor.conf.js","devServerTarget": "xilo:serve"
          }
        },"options": {
            "tsConfig": [
              "e2e/tsconfig.e2e.json"
            ],"exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    }
  },"defaultProject": "xilo","schematics": {
    "@schematics/angular:class": {
      "spec": false
    },"@schematics/angular:component": {
      "spec": false,"inlinestyle": true,"inlineTemplate": true,"prefix": "app","styleext": "css"
    },"@schematics/angular:directive": {
      "spec": false,"prefix": "app"
    },"@schematics/angular:guard": {
      "spec": false
    },"@schematics/angular:module": {
      "spec": false
    },"@schematics/angular:pipe": {
      "spec": false
    },"@schematics/angular:service": {
      "spec": false
    }
  }
}

server.ts

// These are important and needed before anything else
import 'zone.js/dist/zone-node';
import 'reflect-Metadata';

import { enableProdMode } from '@angular/core';

import * as express from 'express';
import { join } from 'path';

// Faster server renders w/ Prod mode (dev mode never needed)
enableProdMode();

// Express server
const app = express();

const PORT = process.env.PORT || 4000;
const disT_FOLDER = join(process.cwd(),'dist');

// * NOTE :: leave this as require() since this file is built Dynamically from webpack
const { AppServerModuleNgFactory,LAZY_MODULE_MAP } = require('./dist/server/main.bundle');

// Express Engine
import { ngExpressEngine } from '@nguniversal/express-engine';
// Import module map for lazy loading
import { provideModuleMap } from '@nguniversal/module-map-ngfactory-loader';

app.engine('html',ngExpressEngine({
  bootstrap: AppServerModuleNgFactory,providers: [
    provideModuleMap(LAZY_MODULE_MAP)
  ]
}));

app.set('view engine','html');
app.set('views',join(disT_FOLDER,'browser'));

// Todo: implement data requests securely
app.get('/api/*',(req,res) => {
  res.status(404).send('data requests are not supported');
});

// Server static files from /browser
app.get('*.*',express.static(join(disT_FOLDER,'browser')));

// All regular routes use the Universal engine
app.get('*',res) => {
  res.render('index',{ req });
});

// Start up the Node server
app.listen(PORT,() => {
  console.log(`Node server listening on http://localhost:${PORT}`);
});

一切都完全按照Angular Universal方向设置.

任何人都知道为什么我的构建脚本不会生成/ server文件夹?

"build:ssr": "npm run build:client-and-server-bundles && npm run webpack:server"

的package.json

{
  "name": "XXX","version": "XXX","license": "MIT","repository": {
    "type": "git","url": "XXXXX"
  },"engines": {
    "node": "10.7.0","npm": "6.1.0"
  },"scripts": {
    "ng": "ng","start": "node dist/server","build": "ng build","build:client-and-server-bundles": "ng build --prod && ng build --prod --project xilo --output-hashing=all","build:prerender": "npm run build:client-and-server-bundles && npm run webpack:server && npm run generate:prerender","build:ssr": "npm run build:client-and-server-bundles && npm run webpack:server","deploy": "git push origin master && git push heroku master","generate:prerender": "cd dist && node prerender","postinstall": "npm run build:ssr","webpack:server": "webpack --config webpack.server.config.js --progress --colors","serve:prerender": "cd dist/browser && http-server","serve:ssr": "node dist/server"
  },"private": true,"dependencies": {
    "@angular/animations": "6.1.0","@angular/common": "6.1.0","@angular/compiler": "6.1.0","@angular/compiler-cli": "6.1.0","@angular/core": "^6.1.0","@angular/forms": "6.1.0","@angular/http": "6.1.0","@angular/language-service": "6.1.0","@angular/platform-browser": "6.1.0","@angular/platform-browser-dynamic": "6.1.0","@angular/platform-server": "6.1.0","@angular/router": "6.1.0","@nguniversal/express-engine": "^5.0.0-beta.5","@nguniversal/module-map-ngfactory-loader": "^5.0.0-beta.5","@nicky-lenaers/ngx-scroll-to": "^0.5.0","@types/moment": "^2.13.0","@types/node": "^8.10.21","angular-file": "^0.4.1","angular2-moment": "^1.9.0","classlist.js": "^1.1.20150312","core-js": "^2.5.7","cpy-cli": "^1.0.1","express": "^4.16.3","font-awesome": "^4.7.0","http-server": "^0.10.0","moment": "^2.22.2","ng-circle-progress": "^0.9.9","ng-hotjar": "0.0.13","ng-intercom": "^1.0.0-beta.5-2","ng2-google-charts": "^3.4.0","ng4-geoautocomplete": "^0.1.0","ngx-filter-pipe": "^1.0.2","ngx-loading": "^1.0.14","ngx-pagination": "^3.0.3","reflect-Metadata": "^0.1.10","rxjs": "^6.2.2","rxjs-compat": "^6.2.2","ts-loader": "^4.4.2","typescript": "2.9.2","web-animations-js": "^2.3.1","zone.js": "^0.8.20"
  },"devDependencies": {
    "@angular-devkit/build-angular": "~0.6.8","@angular/cli": "^6.0.8","webpack-cli": "^3.1.0"
  }
}
npm cache clear --force
rm -rf node_modules
npm install

并祈祷.

angular – ionic 4 google-maps 5 beta“TypeError:无法读取属性’BaseClass’的null”

angular – ionic 4 google-maps 5 beta“TypeError:无法读取属性’BaseClass’的null”

我试图使用离子4 google-maps@5.0.0-beta.20

我正在关注这些幻灯片:https://docs.google.com/presentation/d/1zlkmoSY4AzDJc_P4IqWLnzct41IqHyzGkLeyhlAxMDE/edit#slide=id.g282d0a7bfd_0_140

我收到此错误:“TypeError:无法读取属性’BaseClass’的null”

newlocation.page.html:

<ion-content>
  <h3>Ionic GoogleMaps Starter</h3>
  <div id="map_canvas">

  </div>
</ion-content>

newlocation.page.scss:

map_canvas {
  height: 90%;
}

newlocation.page.ts:

import { Component,OnInit } from '@angular/core';
import { Platform } from '@ionic/angular';
import { GoogleMaps,GoogleMap } from '@ionic-native/google-maps';


@Component({
  selector: 'app-newlocation',templateUrl: './newlocation.page.html',styleUrls: ['./newlocation.page.scss'],})
export class NewlocationPage implements OnInit {

  map: GoogleMap;

  constructor(private platform: Platform) { }

  async ngOnInit() {
    await this.platform.ready();
    await this.loadMap();
  }

  loadMap() {
    this.map = GoogleMaps.create('map_canvas');
  }
}

的package.json:

....
"@ionic-native/core": "5.0.0-beta.14","@ionic-native/google-maps": "^5.0.0-beta.20"
....
"cordova-plugin-googlemaps": {
        "API_KEY_FOR_ANDROID": (API-KEY),"PLAY_SERVICES_VERSION": "15.0.1","ANDROID_SUPPORT_V4_VERSION": "27.+"
      }

解决方法

在Ionic V4中,我们需要定义loadMap()方法异步调用,它将返回promise.

async ngOnInit() {
  await this.platform.ready();
  await this.loadMap()
}

今天关于无法在 Google AI Platform 上部署 pytorch 文本分类器模型,错误:无法从“prediction_server_beta.py”中获取 的讲解已经结束,谢谢您的阅读,如果想了解更多关于android – 错误:资源整数/ google_play_services_version(又名app:integer / google_play_services_version)未找到、Angular 2 AOT不起作用.为什么“platformBrowser().bootstrapModuleFactory”使用附加前缀“/ src / linker / ng_module_factory”拉取链接?、Angular 6 Server Side Errror:找不到模块:错误:无法解析’./dist/server/main.bundle’、angular – ionic 4 google-maps 5 beta“TypeError:无法读取属性’BaseClass’的null”的相关知识,请在本站搜索。

本文标签: