From 795efd199cc0bf49d91f42a0992ae0b8984a4c1e Mon Sep 17 00:00:00 2001 From: las1g21 <las1g21@soton.ac.uk> Date: Fri, 29 Nov 2024 15:35:48 +0000 Subject: [PATCH 1/5] Added Sending Files and Connect to Iridis --- .gitignore | 3 +- mona-ssc | 1 + scripts/scene_completion.py | 63 +++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) create mode 160000 mona-ssc create mode 100644 scripts/scene_completion.py diff --git a/.gitignore b/.gitignore index 6b5efc0..2fd82f2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ scripts/360monodepthexecution/rgb.jpg scripts/shifted_t.png scripts/config.ini -*.pyc \ No newline at end of file +*.pyc +.env \ No newline at end of file diff --git a/mona-ssc b/mona-ssc new file mode 160000 index 0000000..a081661 --- /dev/null +++ b/mona-ssc @@ -0,0 +1 @@ +Subproject commit a0816610da9fa1ed52674240d8343b5643f0e25c diff --git a/scripts/scene_completion.py b/scripts/scene_completion.py new file mode 100644 index 0000000..64f23b7 --- /dev/null +++ b/scripts/scene_completion.py @@ -0,0 +1,63 @@ +import paramiko +from dotenv import load_dotenv +from scp import SCPClient +import os + +load_dotenv() +hostname = os.getenv("HOSTNAME") +username = os.getenv("USERNAME") +password = os.getenv("PASSWORD") + +def send_files(shifted_disparity_path, shifted_t_path): + + command = [ + "scp", + shifted_disparity_path, + f"{username}@{hostname}:{os.getenv("REMOTE_INPUT_PATH")}" + ] + try: + subprocess.run(command, check=True) + + except subprocess.CalledProcessError as e: + print(f"Error during SCP: {e}") + return False + + + command = [ + "scp", + shifted_t_path, + f"{username}@{hostname}:{os.getenv("REMOTE_INPUT_PATH")}" + ] + try: + subprocess.run(command, check=True) + + except subprocess.CalledProcessError as e: + print(f"Error during SCP: {e}") + return False + return True + +def get_completed_scene(shifted_disparity_path, shifted_t_path): + if send_files(shifted_disparity_path, shifted_t_path): + + client = paramiko.SSHClient() + client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) + + # Connect to the server + client.connect(hostname, username=username, password=password) + + # Execute commands on the server + stdin, stdout, stderr = client.exec_command("ls -l") + + print("AHAHAHAHAHAHAH\n") + + # Print the output of the command + print(stdout.read()) + + # Close the SSH connection + client.close() + + else: + return False + + + -- GitLab From c16ac6153c04e6bd414190d17cd0f12ce37ee0b1 Mon Sep 17 00:00:00 2001 From: las1g21 <las1g21@soton.ac.uk> Date: Tue, 3 Dec 2024 15:36:13 +0000 Subject: [PATCH 2/5] Can send files to Iridis --- scripts/scene_completion.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/scripts/scene_completion.py b/scripts/scene_completion.py index 64f23b7..5cb59b6 100644 --- a/scripts/scene_completion.py +++ b/scripts/scene_completion.py @@ -2,6 +2,7 @@ import paramiko from dotenv import load_dotenv from scp import SCPClient import os +import subprocess load_dotenv() hostname = os.getenv("HOSTNAME") @@ -46,18 +47,22 @@ def get_completed_scene(shifted_disparity_path, shifted_t_path): client.connect(hostname, username=username, password=password) # Execute commands on the server - stdin, stdout, stderr = client.exec_command("ls -l") + stdin, stdout, stderr = client.exec_command("cd mona/MDBNet360_GDP/") + stdin, stdout, stderr = client.exec_command("module load conda") + stdin, stdout, stderr = client.exec_command("source activate") + stdin, stdout, stderr = client.exec_command("conda activate sscenv") + stdin, stdout, stderr = client.exec_command("cd mona/MDBNet360_GDP/sbatch --partition=ecsstudents --account=ecsstudents run_obj_job.sh") - print("AHAHAHAHAHAHAH\n") # Print the output of the command print(stdout.read()) # Close the SSH connection client.close() - + else: return False - +out = send_files("C:\\Project\\AVVR-Pipeline-GDP4\\edgenet-360\\Data\\Listening\\shifted-disparity.png", "C:\\Project\\AVVR-Pipeline-GDP4\\edgenet-360\\Data\\Listening\\shifted_t.png") +print(out) \ No newline at end of file -- GitLab From a5244e4a5930ff4d82f4be698061f911f20a4508 Mon Sep 17 00:00:00 2001 From: las1g21 <las1g21@soton.ac.uk> Date: Tue, 3 Dec 2024 18:09:00 +0000 Subject: [PATCH 3/5] Remote Completion --- scripts/scene_completion.py | 78 +++++++++++++++++++++++++++++++------ 1 file changed, 66 insertions(+), 12 deletions(-) diff --git a/scripts/scene_completion.py b/scripts/scene_completion.py index 5cb59b6..9457d47 100644 --- a/scripts/scene_completion.py +++ b/scripts/scene_completion.py @@ -3,6 +3,7 @@ from dotenv import load_dotenv from scp import SCPClient import os import subprocess +import time load_dotenv() hostname = os.getenv("HOSTNAME") @@ -10,6 +11,8 @@ username = os.getenv("USERNAME") password = os.getenv("PASSWORD") def send_files(shifted_disparity_path, shifted_t_path): + # sends two files needed to iridis + # files keep their names. NAMES MUST BE shifted_disparity.png AND shifted_t.png command = [ "scp", @@ -44,25 +47,76 @@ def get_completed_scene(shifted_disparity_path, shifted_t_path): client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) # Connect to the server - client.connect(hostname, username=username, password=password) - - # Execute commands on the server - stdin, stdout, stderr = client.exec_command("cd mona/MDBNet360_GDP/") - stdin, stdout, stderr = client.exec_command("module load conda") - stdin, stdout, stderr = client.exec_command("source activate") - stdin, stdout, stderr = client.exec_command("conda activate sscenv") - stdin, stdout, stderr = client.exec_command("cd mona/MDBNet360_GDP/sbatch --partition=ecsstudents --account=ecsstudents run_obj_job.sh") - + try: + client.connect(hostname, username=username, password=password) + print("SSH connection established.") + + # Check if the connection is active + if client.get_transport().is_active(): + print("Connection is active.") + else: + print("Connection is not active.") + exit(1) # Exit the script if the connection is not active + except Exception as e: + print(f"Failed to connect to {hostname}: {e}") + exit(1) + + stdin, stdout, stderr = client.exec_command( + "cd mona/MDBNet360_GDP/" + + " && module load conda" + + " && source activate" + + " && conda activate ssc_env" + + " && sbatch --partition=ecsstudents --account=ecsstudents run_enhance360_job.sh" + ) + output = stdout.read().decode() + print(output) + + stdin, stdout, stderr = client.exec_command("squeue -lu kproject") + output = stdout.read().decode() + print(output) + + time.sleep(30) + + while "RUNNING" in output: + print("Sleeping for 30") + time.sleep(30) + stdin, stdout, stderr = client.exec_command("squeue -lu kproject") + output = stdout.read().decode() + print(output) - # Print the output of the command - print(stdout.read()) + print("Finish Enhancing") + + stdin, stdout, stderr = client.exec_command( + "cd mona/MDBNet360_GDP/ && ls" + + " && module load conda" + + " && source activate" + + " && conda activate ssc_env" + + " && sbatch --partition=ecsstudents --account=ecsstudents run_obj_job.sh" + ) + output = stdout.read().decode() + print(output) + + stdin, stdout, stderr = client.exec_command("squeue -lu kproject") + output = stdout.read().decode() + print(output) + time.sleep(30) + + while "RUNNING" in output: + print("Sleeping for 30") + time.sleep(30) + stdin, stdout, stderr = client.exec_command("squeue -lu kproject") + output = stdout.read().decode() + print(output) + + print("CLOSING") # Close the SSH connection client.close() + return True else: return False -out = send_files("C:\\Project\\AVVR-Pipeline-GDP4\\edgenet-360\\Data\\Listening\\shifted-disparity.png", "C:\\Project\\AVVR-Pipeline-GDP4\\edgenet-360\\Data\\Listening\\shifted_t.png") +out = get_completed_scene("C:\\Project\\AVVR-Pipeline-GDP4\\edgenet-360\\Data\\Courtyard\\shifted-disparity.png", "C:\\Project\\AVVR-Pipeline-GDP4\\edgenet-360\\Data\\Courtyard\\shifted_t.png") print(out) \ No newline at end of file -- GitLab From 7a1d691b607acfd829401a4aca13762b26b966c9 Mon Sep 17 00:00:00 2001 From: las1g21 <las1g21@soton.ac.uk> Date: Tue, 3 Dec 2024 19:02:28 +0000 Subject: [PATCH 4/5] Downloads Prediction File --- scripts/scene_completion.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/scripts/scene_completion.py b/scripts/scene_completion.py index 9457d47..bda2ac0 100644 --- a/scripts/scene_completion.py +++ b/scripts/scene_completion.py @@ -87,7 +87,7 @@ def get_completed_scene(shifted_disparity_path, shifted_t_path): print("Finish Enhancing") stdin, stdout, stderr = client.exec_command( - "cd mona/MDBNet360_GDP/ && ls" + + "cd mona/MDBNet360_GDP/" + " && module load conda" + " && source activate" + " && conda activate ssc_env" + @@ -109,7 +109,12 @@ def get_completed_scene(shifted_disparity_path, shifted_t_path): output = stdout.read().decode() print(output) - print("CLOSING") + remote_file_path = "/mainfs/ECShome/kproject/mona/MDBNet360_GDP/output/scene_completed_prediction.obj" + local_file_path = "edgenet-360/Data/Input/scene_completed_prediction.obj" + with SCPClient(client.get_transport()) as scp: + scp.get(remote_file_path, local_file_path) # Download file + + print("OUTPUT DOWNLOADED") # Close the SSH connection client.close() return True @@ -118,5 +123,5 @@ def get_completed_scene(shifted_disparity_path, shifted_t_path): return False -out = get_completed_scene("C:\\Project\\AVVR-Pipeline-GDP4\\edgenet-360\\Data\\Courtyard\\shifted-disparity.png", "C:\\Project\\AVVR-Pipeline-GDP4\\edgenet-360\\Data\\Courtyard\\shifted_t.png") -print(out) \ No newline at end of file +# out = get_completed_scene("C:\\Project\\AVVR-Pipeline-GDP4\\edgenet-360\\Data\\Courtyard\\shifted-disparity.png", "C:\\Project\\AVVR-Pipeline-GDP4\\edgenet-360\\Data\\Courtyard\\shifted_t.png") +# print(out) \ No newline at end of file -- GitLab From 9184edebcdf45fc049d9219504a00c352174a438 Mon Sep 17 00:00:00 2001 From: las1g21 <las1g21@soton.ac.uk> Date: Tue, 3 Dec 2024 19:18:49 +0000 Subject: [PATCH 5/5] Allows Access from other files --- scripts/scene_completion.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/scripts/scene_completion.py b/scripts/scene_completion.py index bda2ac0..fdb3fcc 100644 --- a/scripts/scene_completion.py +++ b/scripts/scene_completion.py @@ -24,7 +24,7 @@ def send_files(shifted_disparity_path, shifted_t_path): except subprocess.CalledProcessError as e: print(f"Error during SCP: {e}") - return False + return False, False command = [ @@ -37,7 +37,7 @@ def send_files(shifted_disparity_path, shifted_t_path): except subprocess.CalledProcessError as e: print(f"Error during SCP: {e}") - return False + return False, False return True def get_completed_scene(shifted_disparity_path, shifted_t_path): @@ -56,10 +56,10 @@ def get_completed_scene(shifted_disparity_path, shifted_t_path): print("Connection is active.") else: print("Connection is not active.") - exit(1) # Exit the script if the connection is not active + return False, False except Exception as e: print(f"Failed to connect to {hostname}: {e}") - exit(1) + return False, False stdin, stdout, stderr = client.exec_command( "cd mona/MDBNet360_GDP/" + @@ -117,11 +117,22 @@ def get_completed_scene(shifted_disparity_path, shifted_t_path): print("OUTPUT DOWNLOADED") # Close the SSH connection client.close() - return True + return True, local_file_path else: - return False + return False, False # out = get_completed_scene("C:\\Project\\AVVR-Pipeline-GDP4\\edgenet-360\\Data\\Courtyard\\shifted-disparity.png", "C:\\Project\\AVVR-Pipeline-GDP4\\edgenet-360\\Data\\Courtyard\\shifted_t.png") -# print(out) \ No newline at end of file +# print(out) + +if __name__ == "__main__": + if len(sys.argv) != 3: + print("Usage: python shifter.py <shifted_disparity_path> <shifted_t_path>") + sys.exit(1) + + shifted_disparity_path = sys.argv[1] + shifted_t_path = sys.argv[2] + + saved_path = get_completed_scene(shifted_disparity_path, shifted_t_path) + print(f"Shifted image saved as {saved_path}") \ No newline at end of file -- GitLab