rickwierenga / heartbeat-tutorials

Code for tutorials I have written for Heartbeat
https://heartbeat.fritz.ai/@rickwierenga
MIT License
136 stars 74 forks source link

missing ResNet50 model error #3

Open quantum-fusion opened 3 years ago

quantum-fusion commented 3 years ago

@rickwierenga I tried your demo project, and found that the code has an error, and couldn't find the resnet50 model, so I downloaded the model from Apple. Even after installing the model, I see that your classifier code handler has missing code. I am not sure of the fix, but wanted to better understand your code example. I am interested, and have attached a screen shot from Xcode showing the error.

Screen Shot 2021-01-06 at 11 59 12 AM
rickwierenga commented 3 years ago

I'm 100% not sure what the issue is here, but you could have forgotten to add the project target to the Resnet50.swift file. Let me know if adding a target to the file works.

quantum-fusion commented 3 years ago

@rickwierenga If you notice I included a Resnet50.mlmodel. The Resnet50.swift file that you reference was not included, and if you check your project ClassificationRequest.swift file it is empty. I believe that your ClassificationRequest function is not complete. The way of loading the Resnet50.mlmodel is correct as far as I can tell, but it isn't clear how your ClassificationRequest function should work since I believe the part to load the model belongs there. Please explain. I don't think your project is complete.

quantum-fusion commented 3 years ago

@rickwierenga I checked your writeup article (https://heartbeat.fritz.ai/deploying-core-ml-models-using-vapor-c562a70b1371), and your GitHub code, and the file that you reference Resnet50.swift is missing. Therefore your example will not compile. This is the error. Can you please update the project and compile it without errors?

rickwierenga commented 3 years ago

I did not reference Resnet50.swift anywhere in the tutorial. It is automatically generated by Xcode when you add "App" as a target to the file. You can do this by selecting the file using the file navigator, and pressing alt+command+1. Then find App under Target Membership and make sure it is checked.

If the issue persists, try deleting the Resnet50.mlmodel and adding it again. Make sure "Copy items if needed" is check, and you set up the targets correctly.

Hope that helps.

quantum-fusion commented 3 years ago

I tried adding the Resnet50.mlmodel and adding target membership on MACBook but the command alt+command+1 does not work on MAC, because there is no ALT key. (https://developer.apple.com/forums/thread/662596) see article, but this did not work. The problem of adding a file to a project is that the Xcode has no option for adding a a machine learning model. The second problem I can see is that the CoreML-API project does not have a project file .xcworkspace

If you could please upload your project with the resnet50 model available and a complete .xcworkspace, it would be better to allow me to clone your GITHUB repo than trying to resolve environment and differences in the Xcode platform, because it sounds like you are running on Windows not MAC.

Screen Shot 2021-01-07 at 2 32 44 PM
quantum-fusion commented 3 years ago

See the example I have provided from Apple that has added the Resnet50 model. This project example has a .xcodeproj file that allows me to add the target membership of the resnet50 model by simply dragging it into the desktop Xcode workspace. (https://developer.apple.com/documentation/vision/classifying_images_with_vision_and_core_ml).

Screen Shot 2021-01-07 at 2 56 30 PM
quantum-fusion commented 3 years ago

@rickwierenga I think the problem is really only that your GitHub repo doesn't have the Xcode project workspace. Other than that me adding the resnet50 model would work just fine dragging it into the project like I did with the example shown. Could you add the Xcode project workspace for CorML-API ? I think that is the actual problem, the project that you provided from GitHub doesn't have a project workspace file. When I opened the project, I did it by %open Package.swift, instead of clicking on the CoreML-API project workspace file which is missing.
I understand that you didn't want to upload the Resnet50 file because of its model size which is too large due to a Github limitation.

quantum-fusion commented 3 years ago

@rickwierenga I figured out how to make a Xcode project workspace(%cd ~/heartbeat-tutorials-master/CoreML-API/CoreML-API swift package generate-xcodeproj )

Screen Shot 2021-01-08 at 5 03 56 PM
quantum-fusion commented 3 years ago

@rickwierenga It says there are errors related to dependencies. (see attached)

Screen Shot 2021-01-08 at 5 02 46 PM
quantum-fusion commented 3 years ago

@rickwierenga I discovered a bug on macOS related to the libressl dylib versioning with the linker. I have opened a ticket with vapor to see if they have a potential workaround. (https://github.com/vapor-community/postgresql/issues/77)

quantum-fusion commented 3 years ago

@rickwierenga Have you seen this dylib dependency error on MACOS Big Sur? I was able to add the resnet50 model as membership to the project, and create the xcodeproj workspace.

Screen Shot 2021-02-14 at 11 28 00 AM

I was able to download the Resnet model and create the xcodeproject file. % swift package generate-xcodeproj % xcodebuild -list -project CoreML-API.xcodeproj % xcodebuild -scheme Run build

-- ld: warning: dylib (/usr/local/Cellar/libressl/3.2.3/lib/libssl.dylib) was built for newer macOS version (11.0) than being linked (10.10) ld: warning: dylib (/usr/local/Cellar/libressl/3.2.3/lib/libcrypto.dylib) was built for newer macOS version (11.0) than being linked (10.10) Undefined symbols for architecture x86_64: "_OBJCCLASS$_CIContext", referenced from: objc-class-ref in Classifier.o "_OBJCCLASS$_CIImage", referenced from: objc-class-ref in routes.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

quantum-fusion commented 3 years ago

@rickwierenga I tried %brew install libressl However it does not install the correct version of libssl.dylib and libcrypto.dylib with the clang linker version 11.0 or newer, it is still relying on stale dependencies from clang version 10.10 which are out of date. Any idea where to get the newest dependencies?

quantum-fusion commented 3 years ago

@rickwierenga I tried 1%brew upgrade vapor (https://github.com/vapor/vapor/issues/2104) I tried 2%brew reinstall openssl postgres (https://stackoverflow.com/questions/27264574/import-psycopg2-library-not-loaded-libssl-1-0-0-dylib)

Both 1 and 2 failed, with out upgrading the dependencies.

quantum-fusion commented 3 years ago

@rickwierenga I have alerted the vapor team (https://github.com/vapor/vapor/issues/2104)

quantum-fusion commented 3 years ago

@rickwierenga It is a possibility that the package.swift file is out of date with the wrong version of vapor. See issue (https://github.com/vapor/vapor/issues/2104). Developer states he has removed all openssl dependencies yet your project is trying to resolve openssl and libressl libraries with dylib for crypto.

quantum-fusion commented 3 years ago

@rickwierenga I tried to fix the errors with CIContext and CIImage, by upgrading to vapor4, however the upgrade is more involved. See response from vapor developer. (https://github.com/vapor/vapor/issues/2104)

quantum-fusion commented 3 years ago

@rickwierenga The developer of vapor points out that your project is using vapor3, not vapor4, and the Package.swift file is out of date. He recommends that you upgrade this example project using Vapor4 examples (https://docs.vapor.codes/4.0/upgrading/). See communication history on this issue. (https://github.com/vapor/vapor/issues/2104)

quantum-fusion commented 3 years ago

@rickwierenga Also he points out that he needs Swift 5.3. What version of swift are you using?