amd / Kria-RoboticsAI

MIT License
14 stars 2 forks source link

problems with section 6 ROSAI Applications #4

Open skruglewicz opened 1 month ago

skruglewicz commented 1 month ago

In section 6.1 Launch the install_rosai_file_input.sh script to install and build the application. In step 3 this is what I'm experiencing. setp3. cd /home/ubuntu/KR260-Robotics-AI-Challenge/files/scripts source ./install_rosai_file_input.sh

ERROR GENERATED: File "/usr/lib/python3.10/urllib/request.py", line 643, in http_error_default raise HTTPError(req.full_url, code, msg, hdrs, fp) urllib.error.HTTPError: HTTP Error 403: Forbidden bash: cd: /home/root: No such file or directory colcon: command not found

The code is open source, and available on GitHub. I Installed COLCON with the following command $ sudo apt install python3-colcon-common-extensions

I assume that COLCON did not get installed with ./install_rosai_file_input.sh script?

Now I’m able to run these commands with no COLCON error cd /home/ubuntu/KR260-Robotics-AI-Challenge/files/scripts source ./install_rosai_file_input.sh

HOWEVER NOW I’m getting the following error on step 6 (where is steps 4,5?) by running
source install/local_setup.sh bash: install/local_setup.sh: No such file or directory

Why is the directory or file not found? Where should it be? I am able to run the demo and the The TurtleSim window will pop up but nothing happens as described? I might add that I did not execute the code in both Sections 4.2 and 4.3. I'm not sure if this has anything to do with it Thanks in advance for your help Steve

somayeh-rahimipour commented 1 month ago

Hi Steve,

I wanted to clarify the structure of the install_rosai_file_input.sh script and the README. Some steps in the script are commented out to match the sections in the README for user convenience. If you compare the script with section 6, you’ll find that the steps missing from the README are executed within the script.

Regarding the error "bash: install/local_setup.sh: No such file or directory," this file is typically generated during the build process with colcon build. If it is missing, it suggests that the build process did not complete successfully or the install directory was not created. Here are steps to troubleshoot and resolve this issue:

  1. Verify Directory Structure and Permissions: Ensure the directory /home/root/ros2_ws_fileio exists and is accessible.

  2. Re-run the Build Process: Re-run the build process to ensure that all necessary files are generated:

    cd /home/root/ros2_ws_fileio
    source /opt/ros/humble/setup.bash
    colcon build
  3. Check for Errors During Build: Watch for any errors during the build process. If there are errors, they will prevent the install directory and local_setup.sh file from being created. If you encounter any errors, please let us know.

  4. Verify the Build Output: After the build process completes, verify the contents of the install directory. You should see the local_setup.sh file among other setup files. If the file is not present, the build process did not complete correctly.

Full Script to Ensure All Steps are Correct Below is a full script that encompasses all necessary steps to ensure the build process completes correctly:

#!/bin/bash

# Become super user and set the pynq_venv environment
sudo su
source /etc/profile.d/pynq_venv.sh

# Create test images
python3 /home/ubuntu/KR260-Robotics-AI-Challenge/files/ROSAI/save_images_from_MNIST_dataset.py

# Create workspace folder and copy files
cd /home/root
mkdir -p ros2_ws_fileio
mkdir -p ros2_ws_fileio/src
cp -rf /home/ubuntu/KR260-Robotics-AI-Challenge/files/ROSAI/file_input/rosai_file ros2_ws_fileio/src/
cd ros2_ws_fileio

# Initialize ROS2 environment variables
source /opt/ros/humble/setup.bash

# Build the workspace
colcon build

# Verify the presence of local_setup.sh
if [ -f install/local_setup.sh ]; then
  echo "local_setup.sh found, proceeding..."
  source install/local_setup.sh
  ros2 launch rosai_file rosai_file_demo_launch.py
else
  echo "local_setup.sh not found, build may have failed."
fi

By following these steps, you should be able to identify and resolve the issue preventing the creation of install/local_setup.sh.

We hope this helps, and please feel free to reach out if you have any further questions or need additional assistance.

Somayeh

skruglewicz commented 1 month ago

Thank you I will retry your suggestions. Stay tuned. But I'm still wondering why I had to manually install colcon as stated? Steve K

skruglewicz commented 1 month ago

hello @somayeh-rahimipour I ran the "install_rosai_file_input.sh" script again and there are errors generated in the "save_images_from_MNIST_dataset.py" and creating the Workspace folder with cd /home/root. The directory ros2_ws_fileio was created but under the scripts directory. SO the question now is why is the the image script failing and the the cd cmd failing?

# Create test images
**python3 /home/ubuntu/KR260-Robotics-AI-Challenge/files/ROSAI/save_images_from_MNIST_dataset.py**

# Create workspace folder and copy files
**cd /home/root**

This is the terminal output--- (pynq-venv) root@kria:/home/ubuntu# cd /home/ubuntu/KR260-Robotics-AI-Challenge/files/scripts

(pynq-venv) root@kria:/home/ubuntu/KR260-Robotics-AI-Challenge/files/scripts# ls install_rosai_camera_input.sh install_update_kr260_to_vitisai35.sh install_rosai_file_input.sh ros2_ws install_ros.sh ros2_ws_fileio

(pynq-venv) root@kria:/home/ubuntu/KR260-Robotics-AI-Challenge/files/scripts# source ./install_rosai_file_input.sh

Traceback (most recent call last): File "/home/ubuntu/KR260-Robotics-AI-Challenge/files/ROSAI/save_images_from_MNIST_dataset.py", line 54, in main() File "/home/ubuntu/KR260-Robotics-AI-Challenge/files/ROSAI/save_images_from_MNIST_dataset.py", line 49, in main save_image() File "/home/ubuntu/KR260-Robotics-AI-Challenge/files/ROSAI/save_images_from_MNIST_dataset.py", line 26, in save_image raw_data = mnist.test_images() File "/usr/local/share/pynq-venv/lib/python3.10/site-packages/mnist/init.py", line 176, in test_images return download_and_parse_mnist_file('t10k-images-idx3-ubyte.gz') File "/usr/local/share/pynq-venv/lib/python3.10/site-packages/mnist/init.py", line 143, in download_and_parse_mnist_file fname = download_file(fname, target_dir=target_dir, force=force) File "/usr/local/share/pynq-venv/lib/python3.10/site-packages/mnist/init.py", line 59, in download_file urlretrieve(url, target_fname) File "/usr/lib/python3.10/urllib/request.py", line 241, in urlretrieve with contextlib.closing(urlopen(url, data)) as fp: File "/usr/lib/python3.10/urllib/request.py", line 216, in urlopen return opener.open(url, data, timeout) File "/usr/lib/python3.10/urllib/request.py", line 525, in open response = meth(req, response) File "/usr/lib/python3.10/urllib/request.py", line 634, in http_response response = self.parent.error( File "/usr/lib/python3.10/urllib/request.py", line 563, in error return self._call_chain(args) File "/usr/lib/python3.10/urllib/request.py", line 496, in _call_chain result = func(args) File "/usr/lib/python3.10/urllib/request.py", line 643, in http_error_default raise HTTPError(req.full_url, code, msg, hdrs, fp) urllib.error.HTTPError: HTTP Error 403: Forbidden bash: cd: /home/root: No such file or directory Starting >>> rosai_file Finished <<< rosai_file [8.13s]

Summary: 1 package finished [11.0s] (pynq-venv) root@kria:/home/ubuntu/KR260-Robotics-AI-Challenge/files/scripts/ros2_ws_fileio# ls build install log src

somayeh-rahimipour commented 1 month ago

Hi Steve,

Based on the terminal output, the script save_images_from_MNIST_dataset.py is trying to download the MNIST dataset but fails with a 403 HTTP Error. This means the request to download the dataset is forbidden. There could be a few possibilities:

1. Check Internet Connection It's possible that the internet connection might block access to the URL used by the mnist library to download the dataset. To resolve it, please check the internet connection:

2. Manually Verify URL Access Locate the URL used by the mnist library to download the dataset. You can find this in the mnist library code. Try to manually access this URL from a browser or using a command-line tool like wget or curl on the board:

wget http://yann.lecun.com/exdb/mnist/t10k-images-idx3-ubyte.gz

If the URL access is blocked or results in a 403 error, this confirms the issue is with URL restrictions, or changes in how the dataset is hosted. You can use an alternative library like tensorflow or keras to download the MNIST dataset. Here’s how you can modify the script to use tensorflow to download the MNIST dataset:

import tensorflow as tf
import numpy as np
import os
import cv2

def save_image():
    (train_images, train_labels), (test_images, test_labels) = tf.keras.datasets.mnist.load_data()
    normalized_data = np.asarray(test_images / 255, dtype=np.float32)
    test_data = np.expand_dims(normalized_data, axis=3)
    num_pics = 100

    output_folder = "/home/ubuntu/images/rosai_file_demo_test_images"
    if not os.path.exists(output_folder):
        os.makedirs(output_folder)

    for i in range(num_pics):
        image_to_save = (255 * test_data[i]).astype(np.uint8)
        filename = f"{output_folder}/mnist_image_{i}.jpg"
        success = cv2.imwrite(filename, image_to_save)

def main(args=None):
    save_image()

if __name__ == '__main__':
    main()

Alternative Approach: Use a Local Copy of the MNIST Dataset If internet access is restricted, another approach is to use a local copy of the MNIST dataset. Here’s how you can modify the script to load the dataset from a local file:

Download the Dataset Locally

Modify the Script to Load Locally Save the MNIST dataset as .npy files or use the original .gz files. Here's an example of how to modify the script to load the dataset from local files:

import numpy as np
import os
import cv2

def load_mnist_local(file_path):
    with open(file_path, 'rb') as f:
        return np.load(f)

def save_image():
    raw_data = load_mnist_local('/home/ubuntu/mnist_data/t10k-images-idx3-ubyte.npy')
    normalized_data = np.asarray(raw_data / 255, dtype=np.float32)
    test_data = np.expand_dims(normalized_data, axis=3)
    num_pics = 100

    output_folder = "/home/ubuntu/images/rosai_file_demo_test_images"
    if not os.path.exists(output_folder):
        os.makedirs(output_folder)

    for i in range(num_pics):
        image_to_save = (255 * test_data[i]).astype(np.uint8)
        filename = f"{output_folder}/mnist_image_{i}.jpg"
        success = cv2.imwrite(filename, image_to_save)

def main(args=None):
    save_image()

if __name__ == '__main__':
    main()

This script assumes you have manually downloaded and converted the MNIST dataset to .npy format and placed it in /home/ubuntu/mnist_data/.

I also strongly recommend you follow all the steps (from section 1) one by one, especially when you need to be a super user and set the environment before running some commands.

Please let me know if any of these approaches solve your issue.

Best, Somayeh

skruglewicz commented 1 month ago

Hi @somayeh-rahimipour I'm a bit confused on why I'm getting the Forbidden error as you suggest in option2. it is a restriction and if I try to access the sit from a browser on my PC on the same network as the Kit I get the forbidden error. Off the web site selecting the Highlighted file as described below:

image image

I'm not sure why I don't have access? how do the others following THIS tutorial? I'm using the same Kit, the KR260? There must be a way to login to the site ? but I'm not familiar? can you access the site? Thanks for the information. STEVE K