NOT ABLE DO EDIT THE FILE detectNet.cpp

I am trying to edit the detectNet.cpp file as I would like to change the colors for the detection boxes, however when I edit them and then run the docker, when I open my model with TensorFlow, or check the edited file inside the docker, it is the original one, not the one I did edit, how come? anyone had the same problem and know how to solve this?

Hi @fratanto, after you shutdown the container, changes you made to the files are lost (unless these files were mounted outside of the container). The /jetson-inference/c/detectNet.cpp file is a core source file and is not mounted outside of container (unlike the models and test images)

After you make the edits and before you shutdown your container, you can run sudo docker commit <container-id> jetson-inference:my_tag from another terminal that’s running outside of container. It will then save your changes to jetson-inference:my_tag. You can find the container-id by running sudo docker ps -a.

Then when you go to start container again, you can do docker/run.sh --container jetson-inference:my_tag and it will start your new container instead with the changes you previously made.

1 Like

How would I execute my model then, because when I run my model with TensorRT, every change I make doe snot seem to appear, not even if I make the code impossible to compile and leave some errors, what would the command be to run my model with the new changes?

Hi @fratanto, after you made changes to the cpp source code in the container, did you run the following to build the code in the container again?

cd /jetson-inference/build
make
make install

Alternatively, if you can’t get this to work what you can do is build your own version of jetson-inference container. You can edit the source code outside of container (in the repo that you cloned on your device), and then run docker/build.sh

1 Like

I have done what you suggested, unfortunately, when I tried those lines in my container, it id not work, therefore I built my own version of container, however, when ran “docker/build.sh” it download a lot of packages, and deleted my model and tests, despite that still not working as when I try to run the makefile, inside the “jetson-inference/build” it says that “No makefile found. Stop”.
Anyway to solve this?

If you build your own container, then you would first make the edits to detectNet.cpp outside the container. Then when you build the container with docker/build.sh, it will copy your changes in and compile it. The container should not then require further modification like before. If you make further changes to detectNet.cpp, do it outside of the container, and then run docker/build.sh again.

Sorry I forgot to warn that it deletes the models when you run docker/build.sh. It does this so these models aren’t copied into the container (unnecessarily increasing the size of the container), because they automatically get mounted from the host.

How could I then avoid that it deletes my models?

You can comment out these rm -rf commands in the docker/build.sh script:

https://github.com/dusty-nv/jetson-inference/blob/2fb798e3e4895b51ce7315826297cf321f4bd577/docker/build.sh#L40

However this will add additional size to your container unnecessarily, because the models will be copied into container. So my recommendation is to store your models elsewhere when you run docker/build.sh, and when you are done you can put them back in place. They will then be mounted into the container automatically.

I have managed to make work the
cd /jetson-inference/build
make
make install
However when I run it outside the container, only then would tell me if there is an error in the code, despite that, even though I try to change few lines of code, even if it is text(in the LogVerbose in the detectnet.cpp file) just to receive a feedback that my changes actually appear, but nothing really happens except that now if I compile the code outside the container shows if there is an error in the code.
Any other final suggestion?

If you are running this inside the container, then it is building the copy of the source that is already inside the container. So you may not have modified that source inside the container.

For sanity, you can make your code changes outside the container, and then run docker/build.sh. It will setup/build the container with the source you edited outside of the container. Simply running make && make install outside of container does not build the container - you need to run docker/build.sh to do that.

After building the docker again, would I run the docker normally(docker7run.sh) or would I be using the commands that suggested in the first reply?
sudo docker commit jetson-inference:my_tag
docker/run.sh --container jetson-inference:my_tag

You would run the docker normally with docker/run.sh

The initial directions from the first reply were if you edited the existing container in-place. But now you have re-built it already.

1 Like

I have built the docker, however, it gives me some errors at the end.
What could it be?

Ah, ok. You need to set your default docker-runtime to nvidia like shown here: https://github.com/dusty-nv/jetson-containers#docker-default-runtime

Then reboot or restart your docker service. Then try docker/build.sh again.

1 Like

I have done what you suggested, I have built the docker with no errors, however when I run the docker normally “docker/run.sh”, it still is the same, the detectNet.cpp file and the detectnet.cpp file, when I view the from the container using “cat detectNet.cpp” command, it shows the original version without my edits, and indeed when I run my model, it still is the same with no changes, I also tried to change a bit of the text from the detectnet.cpp file, just to see some feedback, but nothing, it does not seem to change, no matter what I do.
I am trying to change the bounding box colors, nothing that complicated too.
Any final suggestions, which still I have not tried?

OK - let’s step back for a second and ignore the Docker. Make a change to detectnet.cpp or detectNet.cpp outside of Docker. Then if you build the project outside of Docker, do your changes take effect when you run detectnet program outside of Docker?

# run this outside of container
cd jetson-inference/build
make
sudo make install
cd aarch64/bin
./detectnet images/input.jpg images/test/output.jpg

Then if that works as expected, run docker/build.sh again. If you run sudo docker images, do you see the updated jetson-inference container with a recent ‘created’ date? Can you then try docker/run.sh and post the log of it starting?

Yes, if i make the changes outside the docker and then run those commands to test if they took place, it works, except for the bounding color text, but it could be a code problem, however if I change the text in the detectnet.cpp and then run outside the docker a test, it works.

I then built the docker again and checked in the history if the update was there, and it was, except that when I ran the docker after built, it still did not change, even though outside the docker, it did.

I will attach the picture here below:

Also, would you mind telling me if this is correct?
I am trying as said to change the bounding color boxes as I only have two classes, the colours are yellow and green apparently, and I would like to change the green to red, I guess I am in the right spot, but maybe I am wrong(?)

Hmm ok. For some reason, it is still running the original container from Dockerhub (even though the script looks for local container). Can you try running it like this instead? This should run the local container that you just built:

docker/run.sh -c jetson-inference:r32.5.0

Then see if your changes are in there.

I think you want to edit the code slightly above this, at line 486:

https://github.com/dusty-nv/jetson-inference/blob/2fb798e3e4895b51ce7315826297cf321f4bd577/c/detectNet.cpp#L486

for( int i=0; i < numClasses; i++ )
{
	if( n == 0 )
	{
		mClassColors[0][i*4+0] = 255;
		mClassColors[0][i*4+1] = rgb[1]; = 99;
		mClassColors[0][i*4+2] = rgb[2]; = 71;
		mClassColors[0][i*4+3] = 255;
     }
	else if( n == 1 )
	{
		mClassColors[0][i*4+0] = 207;
		mClassColors[0][i*4+1] = rgb[1]; = 74;
		mClassColors[0][i*4+2] = rgb[2]; = 69;
		mClassColors[0][i*4+3] = 127;
	}
	else
	{
		uint8_t rgb[] = {0,0,0};
		GenerateColor(i, rgb);

		mClassColors[0][i*4+0] = rgb[0];
		mClassColors[0][i*4+1] = rgb[1];
		mClassColors[0][i*4+2] = rgb[2];
		mClassColors[0][i*4+3] = DETECTNET_DEFAULT_ALPHA; 

		//printf(LOG_TRT "color %02i  %3i %3i %3i %3i\n", i, (int)r, (int)g, (int)b, (int)alpha);
	}
}

Also note that the alpha values should be in the range of [0, 255]

1 Like