我训练了一个张量流模型来预测输入文本的下一个单词。我将其保存为.h5文件。
我可以在另一个 python 代码中使用该模型来预测单词,如下所示:
import numpy as np
from tensorflow.keras.preprocessing.text import Tokenizer
from tensorflow.keras.preprocessing.sequence import pad_sequences
from keras.models import load_model
model = load_model('model.h5')
model.compile(
loss = "categorical_crossentropy",
optimizer = "adam",
metrics = ["accuracy"]
)
data = open("dataset.txt").read()
corpus = data.lower().split("\n")
tokenizer = Tokenizer()
tokenizer.fit_on_texts(corpus)
seed_text = input()
sequence_text = tokenizer.texts_to_sequences([seed_text])[0]
padded_sequence = np.array(pad_sequences([sequence_text], maxlen = 11 -1))
predicted = np.argmax(model.predict(padded_sequence))
Run Code Online (Sandbox Code Playgroud)
有没有一种方法可以让我直接在 flutter 中使用该模型,我可以从 TextField() 获取输入并按下按钮,显示预测的单词?
我有以下代码,我从 firebase 存储中获取图像作为图像。现在,我想将此图像存储在我的 CachedNetworkImage 中,这样我就不必每次都从数据库中获取它。由于cachednetworkimage需要一个URL并且我正在获取图像,因此如何使用cachednetworkimage?
这是我的代码;
final FirebaseStorage storage = FirebaseStorage(
app: Firestore.instance.app,
storageBucket: 'gs://my-project.appspot.com');
Uint8List imageBytes;
String errorMsg;
_MyHomePageState() {
storage.ref().child('selfies/me2.jpg').getData(10000000).then((data) =>
setState(() {
imageBytes = data;
})
).catchError((e) =>
setState(() {
errorMsg = e.error;
})
);
}
@override
Widget build(BuildContext context) {
var img = imageBytes != null ? Image.memory(
imageBytes,
fit: BoxFit.cover,
) : Text(errorMsg != null ? errorMsg : "Loading...");
return new Scaffold(
appBar: new AppBar(
title: new Text(widget.title),
),
body: new ListView(
children: <Widget>[
img, …Run Code Online (Sandbox Code Playgroud) 有什么想法为什么 Cloud Firestore 连接对我的客户来说很慢,但对我来说却几乎是即时的?选择的 Firebase 服务器是 europe-west3,我的客户在英国,我在罗马尼亚。
根据 speedtest.net 的数据,他的下载速度相对较好,但从 Cloud Firestore 下载数据非常慢。即使是6个文档,总共8个小字段,加载速度也极其缓慢。
我有以下问题。我是 flutter 和 firebase 的新手,我该如何修复它。谢谢
void _handleFirebase() async {
GoogleSignInAuthentication googleAuth = await _currentUser.authentication;
final AuthCredential credential = GoogleAuthProvider.getCredential(
idToken: googleAuth.idToken, accessToken: googleAuth.accessToken);
final FirebaseUser firebaseUser =
await firebaseAuth.signInWithCredential(credential);
if (firebaseUser != null) {
print('Login');
}
Run Code Online (Sandbox Code Playgroud)
和问题表明
没有为类型“GoogleAuthProvider”定义方法“getCredential”。尝试将名称更正为现有方法的名称,或定义名为“getCredential”的方法。
这是我的 pubspec.yaml
cupertino_icons: ^1.0.2
firebase_auth: ^1.0.0
google_sign_in: ^5.0.0
firebase_database: ^6.1.0
rflutter_alert: ^1.1.0
Run Code Online (Sandbox Code Playgroud) 我正在使用 flutter socket io 与运行 node/express 的服务器进行通信。
服务器代码:
var express = require('express');
var bodyParser = require('body-parser')
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var mongoose = require('mongoose');
app.use(express.static(__dirname));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}))
var Message = mongoose.model('Message',{
name : String,
message : String
})
app.get('/', (req, res) =>{
res.send("Hello");
});
io.on('connection', () =>{
console.log('a user is connected')
});
var server = http.listen(8080, "<MyServerIP>", () => {
console.log('server is running on port', server.address().port);
});
Run Code Online (Sandbox Code Playgroud)
我的颤振代码:
connect() async { …Run Code Online (Sandbox Code Playgroud) 使用flutter doctor我知道 flutter 无法找到 google-chrome 可执行文件。我用的是鱼壳。我在/中设置了环境变量。config/fish 使用set CHROME_EXECUTABLE /usr/bin/google-chrome-stable医生所说的命令,但没有帮助。
我正在尝试发出put请求以使用GetConnect更新用户配置文件。用户个人资料采用一些普通的 JSON 字段和一个用于个人资料图片的MultipartFile 。
这是我的ProfileProvider类:
class ProfileProvider extends GetConnect {
Future<ProfileModel> updateProfile({
String name,
String email,
String address,
File avatar,
}) async {
final headers = {
"Authorization": "Bearer $token",
"Content-Type": "application/json",
"Accept": "application/json",
};
String fileName = avatar.path.split("/").last;
final form = FormData({
"name": name,
"email": email,
"address": address,
"avatar": MultipartFile(avatar, filename: fileName),
});
final response = await put(url, form, headers: headers);
if (response.statusCode == 200) {
final profileModel = ProfileModel.fromJson(response.bodyString);
return profileModel;
} …Run Code Online (Sandbox Code Playgroud) 通常,异步操作中发生的堆栈跟踪首先会被切断await(异步挂起)。
所以,我用来Chain.capture获取完整的痕迹。
Chain.capture(() {
runApp(rootWidget);
}, onError: (dynamic error, dynamic stackTrace) {
reportError(error, stackTrace);
});
Run Code Online (Sandbox Code Playgroud)
然而,Flutter 似乎不喜欢它,有时会抛出:
I/flutter ( 6384): The following assertion was thrown running a test (but after the test had completed):
I/flutter ( 6384): Got a stack frame from package:stack_trace, where a vm or web frame was expected. This can happen if
I/flutter ( 6384): FlutterError.demangleStackTrace was not set in an environment that propagates non-standard stack
I/flutter ( 6384): traces to the framework, …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 flutter_inappwebviewplugin 创建一个 flutter web 应用程序。在应用程序中,我添加了一个用于文件上传的 dropzone 插件。此功能在浏览器和 Android 应用程序上都运行良好。但在android应用程序中,当用户上传文件时,我试图请求文件存储和相机权限。如果用户允许访问存储,则只有用户可以在应用程序上上传文件。
为了启用相机的使用,我遵循这个
有没有可能检查设备是否支持 Flutter 上的 eSim?
我知道这可以通过 Flutter Platform Channels 来完成,但我对 Flutter 解决方案特别感兴趣。
flutter ×10
dart ×3
firebase ×2
flutter-web ×2
archlinux ×1
file-upload ×1
flutter-getx ×1
image ×1
node.js ×1
python ×1
socket.io ×1
tensorflow ×1