Weired output image on inference

I’m trying to inference image with upscaling model in flutter. but output image is not as expected.
Its seems problem in normalize or in output to image.

Orginal Image: https://i.sstatic.net/AJX5gj48.png

Output Image: https://i.sstatic.net/A2u3ahd8.png

Model Shape:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Model input shape: ['batch_size', 3, 'width', 'height']
Model output shape: ['batch_size', 3, 'width', 'height']
</code>
<code>Model input shape: ['batch_size', 3, 'width', 'height'] Model output shape: ['batch_size', 3, 'width', 'height'] </code>
Model input shape: ['batch_size', 3, 'width', 'height']
Model output shape: ['batch_size', 3, 'width', 'height']

Logs:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>flutter: Is normalized: true
flutter: Image normalized successfully.
flutter: Input tensor created successfully.
flutter: Width: 1428, Height: 804, Channel: 3
</code>
<code>flutter: Is normalized: true flutter: Image normalized successfully. flutter: Input tensor created successfully. flutter: Width: 1428, Height: 804, Channel: 3 </code>
flutter: Is normalized: true
flutter: Image normalized successfully.
flutter: Input tensor created successfully.
flutter: Width: 1428, Height: 804, Channel: 3

I tried this code and out of scope now.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> Future<void> inference() async {
if (selectedImage == null) {
debugPrint('No image selected');
return;
}
if (selectedImage != null) {
Float32List? floatData;
try {
img.Image normalizedImage =
img.normalize(selectedImage!, min: 0, max: 255);
Uint8List imageData = normalizedImage.getBytes(order: img.ChannelOrder.rgb);
floatData = Float32List.fromList(
imageData.map((byte) => byte / 255.0).toList());
debugPrint("Is normalized: ${isNormalized(floatData)}");
} catch (e) {
debugPrint("Error during normalization: $e");
}
final shape = [1, 3, selectedImage!.width, selectedImage!.height];
debugPrint('Image normalized successfully.');
final inputOrt =
OrtValueTensor.createTensorWithDataList(floatData!, shape);
final inputs = {'input': inputOrt};
debugPrint('Input tensor created successfully.');
final runOptions = OrtRunOptions();
final outputs = await ortSession.runAsync(runOptions, inputs);
inputOrt.release();
runOptions.release();
outputs?.forEach((element) {
final outputValue = element?.value;
if (outputValue is List<List<List<List<double>>>>) {
img.Image generatedImage = generateImageFromOutput(outputValue);
showDialog(
context: context,
builder: (BuildContext context) {
return Dialog(
child: SizedBox(
width: generatedImage.width.toDouble(),
height: generatedImage.height.toDouble(),
child: Image.memory(
Uint8List.fromList(img.encodePng(generatedImage)),
fit: BoxFit.contain,
),
),
);
},
);
} else {
debugPrint("Output is of unknown type");
}
element?.release();
});
}
}
img.Image generateImageFromOutput(
List<List<List<List<double>>>> outputValue) {
int width = outputValue[0][0].length;
int height = outputValue[0][0][0].length;
int channel = outputValue[0].length;
print("Width: $width, Height: $height, Channel: $channel");
// Create the image
img.Image generatedImage = img.Image(width: width, height: height);
// Set pixel values
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
// Extract RGB values from the output tensor data
int r = (outputValue[0][0][x][y] * 255).toInt().clamp(0, 255);
int g = (outputValue[0][1][x][y] * 255).toInt().clamp(0, 255);
int b = (outputValue[0][2][x][y] * 255).toInt().clamp(0, 255);
// Set pixel value in the generated image
generatedImage.setPixelRgb(x, y, r, g, b);
}
}
return generatedImage;
}
</code>
<code> Future<void> inference() async { if (selectedImage == null) { debugPrint('No image selected'); return; } if (selectedImage != null) { Float32List? floatData; try { img.Image normalizedImage = img.normalize(selectedImage!, min: 0, max: 255); Uint8List imageData = normalizedImage.getBytes(order: img.ChannelOrder.rgb); floatData = Float32List.fromList( imageData.map((byte) => byte / 255.0).toList()); debugPrint("Is normalized: ${isNormalized(floatData)}"); } catch (e) { debugPrint("Error during normalization: $e"); } final shape = [1, 3, selectedImage!.width, selectedImage!.height]; debugPrint('Image normalized successfully.'); final inputOrt = OrtValueTensor.createTensorWithDataList(floatData!, shape); final inputs = {'input': inputOrt}; debugPrint('Input tensor created successfully.'); final runOptions = OrtRunOptions(); final outputs = await ortSession.runAsync(runOptions, inputs); inputOrt.release(); runOptions.release(); outputs?.forEach((element) { final outputValue = element?.value; if (outputValue is List<List<List<List<double>>>>) { img.Image generatedImage = generateImageFromOutput(outputValue); showDialog( context: context, builder: (BuildContext context) { return Dialog( child: SizedBox( width: generatedImage.width.toDouble(), height: generatedImage.height.toDouble(), child: Image.memory( Uint8List.fromList(img.encodePng(generatedImage)), fit: BoxFit.contain, ), ), ); }, ); } else { debugPrint("Output is of unknown type"); } element?.release(); }); } } img.Image generateImageFromOutput( List<List<List<List<double>>>> outputValue) { int width = outputValue[0][0].length; int height = outputValue[0][0][0].length; int channel = outputValue[0].length; print("Width: $width, Height: $height, Channel: $channel"); // Create the image img.Image generatedImage = img.Image(width: width, height: height); // Set pixel values for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { // Extract RGB values from the output tensor data int r = (outputValue[0][0][x][y] * 255).toInt().clamp(0, 255); int g = (outputValue[0][1][x][y] * 255).toInt().clamp(0, 255); int b = (outputValue[0][2][x][y] * 255).toInt().clamp(0, 255); // Set pixel value in the generated image generatedImage.setPixelRgb(x, y, r, g, b); } } return generatedImage; } </code>
  Future<void> inference() async {
    if (selectedImage == null) {
      debugPrint('No image selected');
      return;
    }

    if (selectedImage != null) {
      Float32List? floatData;
      try {
        img.Image normalizedImage =
            img.normalize(selectedImage!, min: 0, max: 255);
        Uint8List imageData = normalizedImage.getBytes(order: img.ChannelOrder.rgb);
        floatData = Float32List.fromList(
            imageData.map((byte) => byte / 255.0).toList());
        debugPrint("Is normalized: ${isNormalized(floatData)}");
      } catch (e) {
        debugPrint("Error during normalization: $e");
      }

      final shape = [1, 3, selectedImage!.width, selectedImage!.height];

      debugPrint('Image normalized successfully.');

      final inputOrt =
          OrtValueTensor.createTensorWithDataList(floatData!, shape);

      final inputs = {'input': inputOrt};

      debugPrint('Input tensor created successfully.');

      final runOptions = OrtRunOptions();
      final outputs = await ortSession.runAsync(runOptions, inputs);

      inputOrt.release();
      runOptions.release();

      outputs?.forEach((element) {
        final outputValue = element?.value;

        if (outputValue is List<List<List<List<double>>>>) {
          img.Image generatedImage = generateImageFromOutput(outputValue);
          showDialog(
            context: context,
            builder: (BuildContext context) {
              return Dialog(
                child: SizedBox(
                  width: generatedImage.width.toDouble(),
                  height: generatedImage.height.toDouble(),
                  child: Image.memory(
                    Uint8List.fromList(img.encodePng(generatedImage)),
                    fit: BoxFit.contain,
                  ),
                ),
              );
            },
          );
        } else {
          debugPrint("Output is of unknown type");
        }
        element?.release();
      });
    }
  }

  img.Image generateImageFromOutput(
      List<List<List<List<double>>>> outputValue) {
    int width = outputValue[0][0].length;
    int height = outputValue[0][0][0].length;
    int channel = outputValue[0].length;

    print("Width: $width, Height: $height, Channel: $channel");

    // Create the image
    img.Image generatedImage = img.Image(width: width, height: height);

    // Set pixel values
    for (int y = 0; y < height; y++) {
      for (int x = 0; x < width; x++) {
        // Extract RGB values from the output tensor data
        int r = (outputValue[0][0][x][y] * 255).toInt().clamp(0, 255);
        int g = (outputValue[0][1][x][y] * 255).toInt().clamp(0, 255);
        int b = (outputValue[0][2][x][y] * 255).toInt().clamp(0, 255);

        // Set pixel value in the generated image
        generatedImage.setPixelRgb(x, y, r, g, b);
      }
    }
    return generatedImage;
  }

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật