ML 套件占用太多内存 [Android]
ML kit take too much Memory [Android]
我正在尝试使用图像内容 [onDevice Mode] 来描述一些图像,但它占用太多内存,如果我在同一个应用程序中尝试了很多图像,它 崩溃.
我不知道为什么会这样,但它总是抛出 OutOfMemoryError 异常。
我的图片大约有 1-2 MB 大小。
当我用谷歌搜索异常时,我启用了 android:largeHeap="true"
但在尝试 2 张图片后仍然崩溃。
我也尝试使用 System.gc();
从 vars 中释放内存,但仍然占用太多内存。
这是我在设备上使用的代码:
在 onCreate() 中;
detector = FirebaseVision.getInstance()
.getVisionLabelDetector();
当点击按钮
detector.detectInImage(image)
.addOnSuccessListener(
new OnSuccessListener<List<FirebaseVisionLabel>>() {
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
public void onSuccess(List<FirebaseVisionLabel> labels) {
Toast.makeText(MainActivity.this, "Done", Toast.LENGTH_SHORT).show();
setResult(labels, "onDevice Result : ", before);
System.gc();
}
})
.addOnFailureListener(
new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(MainActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
System.out.println("Error: " + e.getMessage());
}
});
谁能帮帮我?
我的问题是图像质量太高并且没有压缩图像
图像必须在对其进行初始化处理之前进行压缩
我正在尝试使用图像内容 [onDevice Mode] 来描述一些图像,但它占用太多内存,如果我在同一个应用程序中尝试了很多图像,它 崩溃.
我不知道为什么会这样,但它总是抛出 OutOfMemoryError 异常。 我的图片大约有 1-2 MB 大小。
当我用谷歌搜索异常时,我启用了 android:largeHeap="true"
但在尝试 2 张图片后仍然崩溃。
我也尝试使用 System.gc();
从 vars 中释放内存,但仍然占用太多内存。
这是我在设备上使用的代码:
在 onCreate() 中;
detector = FirebaseVision.getInstance()
.getVisionLabelDetector();
当点击按钮
detector.detectInImage(image)
.addOnSuccessListener(
new OnSuccessListener<List<FirebaseVisionLabel>>() {
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
public void onSuccess(List<FirebaseVisionLabel> labels) {
Toast.makeText(MainActivity.this, "Done", Toast.LENGTH_SHORT).show();
setResult(labels, "onDevice Result : ", before);
System.gc();
}
})
.addOnFailureListener(
new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(MainActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
System.out.println("Error: " + e.getMessage());
}
});
谁能帮帮我?
我的问题是图像质量太高并且没有压缩图像
图像必须在对其进行初始化处理之前进行压缩