• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - swift : Process UIImage data for use in Firebase custom TFLite model

[复制链接]
菜鸟教程小白 发表于 2022-12-13 04:20:46 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我正在使用 Swift、Firebase 和 Tensorflow 构建图像识别模型。我有一个重新训练过的 MobileNet 模型,该模型将 [1,224,224,3] 的输入数组复制到我的 Xcode 包中,当我尝试从图像中添加数据作为输入时,我收到错误:Input 0 should有 602112 字节,但找到了 627941 字节。 我正在使用以下代码:

    let input = ModelInputs()
    do {
        let newImage = image.resizeTo(size: CGSize(width: 224, height: 224))

        let data = UIImagePNGRepresentation(newImage)

        // Store input data in `data`

        // ...
        try input.addInput(data)
        // Repeat as necessary for each input index
    } catch let error as NSError {
        print("Failed to add input: \(error.localizedDescription)")
    }



    interpreter.run(inputs: input, options: ioOptions) { outputs, error in
        guard error == nil, let outputs = outputs else {
            print(error!.localizedDescription)//ERROR BEING CALLED HERE
            return }
        // Process outputs
        print(outputs)
        // ...
    }

如何将图像数据重新处理为 602112 字节?如果有人可以帮助我,我会很困惑,那就太好了



Best Answer-推荐答案


请查看 Swift 中的快速入门 iOS 演示应用,了解如何使用自定义 TFLite 模型:

https://github.com/firebase/quickstart-ios/tree/master/mlmodelinterpreter

特别是,我认为这是您正在寻找的:

https://github.com/firebase/quickstart-ios/blob/master/mlmodelinterpreter/MLModelInterpreterExample/UIImage%2BTFLite.swift#L47

祝你好运!

关于ios - swift : Process UIImage data for use in Firebase custom TFLite model,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50892298/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap