Skip to content

Model management fixes - #570

Open
harishthakur52 wants to merge 8 commits into
ob-f:masterfrom
3dwesupport:fix/model-management-sync
Open

harishthakur52 wants to merge 8 commits into
ob-f:masterfrom
3dwesupport:fix/model-management-sync

Conversation

@harishthakur52

Copy link
Copy Markdown
Contributor

Problem

Model sync between the apps and Google Drive was causing a lot of issues:

  • Every app was overwriting the full config.json, so models added on one device were getting wiped by another.
  • Android and iOS were saving different type names, and Android crashed after syncing.
  • We weren't checking the model file at all, so a wrong type or size could break the model and crash the app.

#Fixes

  • Sync now only updates the model that changed and leaves the rest of the list as it is.
  • Android and iOS now use the same type names, and bad entries are skipped instead of crashing the app.
  • If the Drive list can't be read, we don't overwrite it. Models added while signed out are uploaded after sign-in so they don't get lost.
  • Type, classes and input size are now read from the .tflite file itself, and unsupported files are rejected.
  • Added long-press delete for user-added models, which removes them everywhere.

@thias15 thias15 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice cleanup. Updating only the changed model and never writing over an unreadable list should fix the lost models. Two things:

  1. An empty list counts as unreadable. On Android writeModelChanges and deleteModelEverywhere stop when the parsed list is empty, so a shared list that really is [] can never be written again. Could a parse error return null and be checked separately from an empty list?
  2. Models added while signed out: after sign-in, user-added models are uploaded to the shared list. If such a model only has a local file path, other devices get an entry they can't download. Is the model file uploaded somewhere I missed? If not, it may be better to skip those entries or upload the file first.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved synchronization races can lose updates or resurrect deleted models, while model validation and inference gaps still permit crashes.

20 open issues
What changed in this PR

This PR updates model management across the robot apps and web playground to improve Drive synchronization, model compatibility checks, and deletion.

Changes:

  • Merges model-specific changes into Drive configuration and normalizes legacy type names.
  • Derives model settings from .tflite files and adds safer detector error handling.
  • Adds permanent-delete actions and localized messages.
File Description
robot/​ios/​OpenBot/​OpenBot/​zh-Hans.lproj/​Localizable.strings Adds Chinese model messages.
robot/​ios/​OpenBot/​OpenBot/​Utils/​Toast.swift Adds an alert helper.
robot/​ios/​OpenBot/​OpenBot/​Utils/​Strings.swift Exposes new localized messages.
robot/​ios/​OpenBot/​OpenBot/​Utils/​Constants.swift Normalizes shared model names.
robot/​ios/​OpenBot/​OpenBot/​Utils/​Common.swift Adds resilient loading and lookup helpers.
robot/​ios/​OpenBot/​OpenBot/​tflite/​Model.swift Adds entry decoding and file inspection.
robot/​ios/​OpenBot/​OpenBot/​tflite/​DetectorFloatYoloV5.swift Makes model parsing throwable.
robot/​ios/​OpenBot/​OpenBot/​tflite/​DetectorFloatYoloV4.swift Checks detector outputs.
robot/​ios/​OpenBot/​OpenBot/​tflite/​DetectorDefault.swift Checks detector output compatibility.
robot/​ios/​OpenBot/​OpenBot/​tflite/​Detector.swift Propagates parsing errors.
robot/​ios/​OpenBot/​OpenBot/​ko.lproj/​Localizable.strings Adds Korean model messages.
robot/​ios/​OpenBot/​OpenBot/​hi.lproj/​Localizable.strings Adds Hindi model messages.
robot/​ios/​OpenBot/​OpenBot/​fr.lproj/​Localizable.strings Adds French model messages.
robot/​ios/​OpenBot/​OpenBot/​es.lproj/​Localizable.strings Adds Spanish model messages.
robot/​ios/​OpenBot/​OpenBot/​en.lproj/​Localizable.strings Adds English model messages.
robot/​ios/​OpenBot/​OpenBot/​de.lproj/​Localizable.strings Adds German model messages.
robot/​ios/​OpenBot/​OpenBot/​Controllers/​runRobot/​RunRobot.swift Avoids forced detector creation.
robot/​ios/​OpenBot/​OpenBot/​Controllers/​ObjectTracking/​ObjectTrackingFragment.swift Reports detector compatibility errors.
robot/​ios/​OpenBot/​OpenBot/​Controllers/​ModelManagement/​PopupWindowView.swift Uses inspected settings when saving.
robot/​ios/​OpenBot/​OpenBot/​Controllers/​ModelManagement/​ModelManagementTable.swift Validates downloads and adds deletion.
robot/​ios/​OpenBot/​OpenBot/​Controllers/​ModelManagement/​BottomSheet.swift Checks temporary imports before saving.
robot/​ios/​OpenBot/​OpenBot/​Authentication/​Authentication.swift Adds per-model Drive updates and deletion.
robot/​android/​app/​src/​test/​java/​org/​openbot/​app/​robot/​tflite/​ModelFileCheckTest.java Tests model classification rules.
robot/​android/​app/​src/​main/​res/​values/​strings.xml Adds default model messages.
robot/​android/​app/​src/​main/​res/​values-zh/​strings.xml Adds Chinese model messages.
robot/​android/​app/​src/​main/​res/​values-ko/​strings.xml Adds Korean model messages.
robot/​android/​app/​src/​main/​res/​values-hi/​strings.xml Adds Hindi model messages.
robot/​android/​app/​src/​main/​res/​values-fr/​strings.xml Adds French model messages.
robot/​android/​app/​src/​main/​res/​values-es/​strings.xml Adds Spanish model messages.
robot/​android/​app/​src/​main/​res/​values-de/​strings.xml Adds German model messages.
robot/​android/​app/​src/​main/​java/​org/​openbot/​app/​robot/​utils/​FileUtils.java Filters entries and restores download links.
robot/​android/​app/​src/​main/​java/​org/​openbot/​app/​robot/​tflite/​Network.java Adds local filename fallback.
robot/​android/​app/​src/​main/​java/​org/​openbot/​app/​robot/​tflite/​ModelFileCheck.java Inspects model tensor metadata.
robot/​android/​app/​src/​main/​java/​org/​openbot/​app/​robot/​tflite/​Model.java Adds legacy aliases and validation.
robot/​android/​app/​src/​main/​java/​org/​openbot/​app/​robot/​tflite/​Detector.java Guards missing model classes.
robot/​android/​app/​src/​main/​java/​org/​openbot/​app/​robot/​objectNav/​ObjectNavFragment.java Makes model filtering null-safe.
robot/​android/​app/​src/​main/​java/​org/​openbot/​app/​robot/​modelManagement/​ModelManagementFragment.java Validates imports and adds permanent deletion.
robot/​android/​app/​src/​main/​java/​org/​openbot/​app/​robot/​modelManagement/​ModelAdapter.java Handles long-press deletion.
robot/​android/​app/​src/​main/​java/​org/​openbot/​app/​robot/​modelManagement/​EditModelDialogFragment.java Restricts settings to inspected values.
robot/​android/​app/​src/​main/​java/​org/​openbot/​app/​robot/​googleServices/​GoogleServices.java Merges Drive changes and handles deletion.
robot/​android/​app/​src/​main/​java/​org/​openbot/​app/​robot/​autopilot/​AutopilotFragment.java Makes model filtering null-safe.
open-code/​src/​utils/​tfliteModel.js Reads and classifies model tensors.
open-code/​src/​utils/​constants.js Removes manual model-type options.
open-code/​src/​utils/​color.js Adds validation-error color.
open-code/​src/​services/​workspace.js Preserves configuration on read failures.
open-code/​src/​services/​googleDrive.js Locates and reads shared configuration.
open-code/​src/​pages/​playground/​index.js Refreshes configuration on entry.
open-code/​src/​components/​inputComponent/​simpleInputComponent.js Displays file-derived model settings.
open-code/​src/​components/​inputComponent/​inputComponent.module.css Styles disabled inputs.
open-code/​src/​components/​bottomBar/​modelUploadingComponent.js Validates uploads and refreshes shared metadata.
open-code/​src/​components/​blockly/​blocks/​customblocks.js Accepts both navigation type names.

Review effort: Balanced

Comment on lines 157 to 158
configData.push(newModelData)
await uploadToGoogleDrive(JSON.stringify(configData), Constants.json).then(async () => {
const settings = (type, classes) => ({type, classes, width: image.shape[2], height: image.shape[1]});

// Driving models take the camera image plus a command (1 value) or a goal (3 values).
if (inputs.length === 2 && outputs.length === 1) {
Comment on lines +551 to +555
if (model.pathType == Model.PATH_TYPE.FILE
|| FileUtils.isUserModel(mActivity, model)) models.add(model);
}
try {
if (!models.isEmpty()) writeModelChanges(driveService, models, false);
Comment on lines +581 to +584
for (Model model : models) applyModelChange(gson, modelList, model, removed);
String modelListContent = gson.toJson(FileUtils.removeInvalidModels(modelList));

if (configFileId != null) updateModelListFile(modelListContent, configFileId);
Comment on lines +494 to +496
if (!googleServices.isSignedIn()) {
deleteModelFromPhone(mItem);
return;
if (configFileId != null) {
modelList = parseModelList(gson, readFile(driveService, configFileId));
// Never write over a list that couldn't be read.
if (modelList.isEmpty()) throw new IOException("Shared model list is unreadable");
Gson gson = new Gson();
String json = gson.toJson(masterList);
System.out.println("filenameId:::" + masterList.indexOf(item1));
googleServices.uploadModelChange(item1, false);
Comment on lines +550 to +552
guard !driveModels.isEmpty else {
print("Drive config.json is unreadable, not updating it")
return
} catch {
print(error.localizedDescription)
// Check a temporary copy; the model is added to the app only on Done.
let checkURL = FileManager.default.temporaryDirectory.appendingPathComponent("model_check.tflite")
}
} else {
}
Authentication.googleAuthentication.updateModelListFile(models: allModels.filter { $0.name == model.name }, removedNames: isRenamed ? [originalName] : [])

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants