diff --git a/.gitignore b/.gitignore index 6b5efc082fa8b5f261078601f901ca8a784b7092..2fd82f2758d73c559bb2fe4bf5f22edac87e2395 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 0000000000000000000000000000000000000000..a0816610da9fa1ed52674240d8343b5643f0e25c --- /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 0000000000000000000000000000000000000000..fdb3fcc0b99b87e3d7cf5ca9f6ef062b89e1c075 --- /dev/null +++ b/scripts/scene_completion.py @@ -0,0 +1,138 @@ +import paramiko +from dotenv import load_dotenv +from scp import SCPClient +import os +import subprocess +import time + +load_dotenv() +hostname = os.getenv("HOSTNAME") +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", + 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, 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, 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 + 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.") + return False, False + except Exception as e: + print(f"Failed to connect to {hostname}: {e}") + return False, False + + 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("Finish Enhancing") + + 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_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) + + 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, local_file_path + + else: + 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) + +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