Week 5: Going to Win-“dows” Victories
March 29, 2024
Day N of building OpenSFM, I finally got it working on my WSL. Not Windows PowerShell, Windows Subsystem for Linux. In other words, Linux was the easiest to build OpenSFM on.
Building OpenSFM on Linux
To fix my installation error from last week,
Windows button > search Turn Windows features on or off > enable Virtual Machine Platform > restart computer
Now, I clone the repository, then run the commands from the Dockerfile for Ubuntu by adding “sudo” in front.
sudo apt-get update sudo apt-get install -y build-essential cmake git libeigen3-dev libopencv-dev libceres-dev python3-dev python3-numpy python3-opencv python3-pip python3-pyproj python3-scipy python3-yaml curl sudo apt-get clean sudo rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* sudo pip3 install -r requirements.txt sudo python3 setup.py build
To find the files stored in WSL, go to File Explorer, scroll down to Linux tab > Ubuntu > home > yourusername > OpenSfM. You can open this in your choice of code editor (VSCode, in my case).
Note that when you edit then save a file, you might get an error that you don’t have permission to do so.
To get access, run this command for your file:
sudo chown czhang /home/czhang/OpenSfM/filename.txt
This is the output from when OpenSFM finishes building. Never seen such beauty in my life.
To test that it worked, I ran it on the sample Berlin dataset.
I linked this project to my original Github fork by running
sudo git remote set-url origin https://username:personalaccesstoken@github.com/Lypho2012/OpenSfM.git
Setting the remote URL to contain your personal access token lets you commit changes without having to enter your personal access token every single time.
Before I get into my work process, there’s a few more tips to note about binary numbers.
Binary – Special Cases
Negative Numbers:
The two conventions for writing negative numbers in binary are sign magnitude and twos complement.
Sign magnitude uses the most significant bit to represent the sign, where 1 represents negative and 0 represents positive. For example:
Decimal Binary
7 0111
-7 1111
Twos complement uses the most significant bit to represent subtracting 2^n, where n is the length of the bit string. You can also convert from the positive to negative form by flipping all the bits and adding 1. For example:
Decimal Binary
7 0111
-7 1001
Floats:
The IEEE-754 is a convention for converting floating point numbers to binary. You can use this WikiHow to learn how it works.
However, there’s an even easier way to work with floats with quantization: multiplying the float by a power of 10 to preserve some digits after the decimal point. This is the method that I’m going to use when performing operations later on.
VSCode Python Debugger
I tried running a test file on its own, but I got an error on the “import opensfm” line that opensfm couldn’t be found. Since the build works and I could even reconstruct the Berlin sample, I suspect the problem might be with permissions since I have to run commands with “sudo” in the Terminal. For now, I decided to try setting up a debugger and running the commands from the Terminal so that I can attach to the process.
Run and Debug on the sidebar (ctrl+shift+d) > dropdown menu at the top > Add Configurations > Python Debugger > Attach Using Process ID
This generates a launch.json file.
Now, put a random input() statement (so that the code process starts but waits for you to attach your debugger) in your code and run it. If you select Python Debugger: Attach Using Process ID from the dropdown menu and click the run button, it should prompt you to pick a process.
For me, this didn’t show up, which I think is a problem with my VSCode, so I will have to either downgrade VSCode or input the process ID manually. There’s a way to see the list of processes by ctrl+shift+p and search Process Explorer, but even when I input the process ID, none of them would connect, so I have to test further.
Another way to use the debugger is to add a Python Debugger: Current File with Arguments configuration. I was trying to test the build statement python3 setup.py build, so I had to add the additional “sudo”: true, “redirectOutput”: true and set “console” to “integratedTerminal.” While this did run, I got an error that the “sphinx” module couldn’t be found, which I think is because this process likely runs the command “python setup.py build” and not “python3 setup.py build.”
What to Expect
For the upcoming week, I’m going to be trying to get the debugger to work so that I can start testing substituting in BSI in the code. I will likely need to create an auxiliary class using BSI as the base because BSI is not suited to work with multi-dimensional matrices. Instead, I will be using the algorithms from NumPy and calling BSI operations instead of the regular vector operations. Of course, since I have figured out the quantization part, this merits a change to the predicted upcoming schedule:
Week 6: Create auxiliary class for BSI arrays and start substituting it in small sections
Week 7: Continue testing and substituting further
Week 8: Try using same numpy algorithms for BSI for bigger operations (determinant, inverse, etc.)
Week 9: If succeeded last week, try for rest of algorithms, else setup conversion from BSI to numpy
Week 10: Write drafts of smaller operations in BSI (drop col, etc.)
Week 11: Runthrough with OpenSFM and collect some data
Week 12: Make presentation
Sources:
https://www.wikihow.com/Convert-a-Number-from-Decimal-to-IEEE-754-Floating-Point-Representation
Leave a Reply
You must be logged in to post a comment.