newRoop commited on
Commit
0438970
Β·
verified Β·
1 Parent(s): 1a690f7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -14
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import subprocess
2
  import sys
3
  import os
 
4
 
5
  def install_tensorflow():
6
  """
@@ -36,7 +37,7 @@ def check_tensorflow_installation():
36
  If not installed, it calls the installation function.
37
  """
38
  try:
39
- import tensorflow as tf
40
  print(f"TensorFlow version: {tf.__version__}")
41
  print("TensorFlow is installed and ready to use.")
42
  return True
@@ -44,20 +45,19 @@ def check_tensorflow_installation():
44
  print("TensorFlow is not installed.")
45
  install_tensorflow()
46
  try:
47
- import tensorflow as tf
48
- print(f"TensorFlow version: {tf.__version__}")
49
- print("TensorFlow is installed and ready to use.")
50
- return True
51
  except ImportError:
52
- return False
53
-
54
-
55
 
56
  if not check_tensorflow_installation():
57
  print("TensorFlow installation failed. Exiting.")
58
  sys.exit(1)
59
 
60
- import tensorflow as tf
 
61
  from tensorflow.keras.layers import Input, Add, Dense, Activation, ZeroPadding2D, BatchNormalization, Flatten, Conv2D, MaxPooling2D, AveragePooling2D, Dropout
62
  from tensorflow.keras.models import Model
63
  from tensorflow.keras.initializers import GlorotUniform
@@ -89,10 +89,20 @@ if IS_COLAB:
89
  test_dir = "test"
90
 
91
  else:
92
- # **IMPORTANT: Update these paths to the actual location of your data!**
93
- train_dir = "./train" # Replace with your actual path
94
- val_dir = "./val" # Replace with your actual path
95
- test_dir = "./test" # Replace with your actual path
 
 
 
 
 
 
 
 
 
 
96
 
97
  if not os.path.exists(train_dir):
98
  print(f"Error: Training data directory not found at {train_dir}")
@@ -346,4 +356,3 @@ except KeyboardInterrupt:
346
  except Exception as e:
347
  print(f"An error occurred during training: {e}")
348
  print("Please check your data and model configuration.")
349
-
 
1
  import subprocess
2
  import sys
3
  import os
4
+ import tensorflow as tf # Import TensorFlow at the top
5
 
6
  def install_tensorflow():
7
  """
 
37
  If not installed, it calls the installation function.
38
  """
39
  try:
40
+ # Import tensorflow here
41
  print(f"TensorFlow version: {tf.__version__}")
42
  print("TensorFlow is installed and ready to use.")
43
  return True
 
45
  print("TensorFlow is not installed.")
46
  install_tensorflow()
47
  try:
48
+ import tensorflow as tf
49
+ print(f"TensorFlow version: {tf.__version__}")
50
+ print("TensorFlow is installed and ready to use.")
51
+ return True
52
  except ImportError:
53
+ return False
 
 
54
 
55
  if not check_tensorflow_installation():
56
  print("TensorFlow installation failed. Exiting.")
57
  sys.exit(1)
58
 
59
+
60
+
61
  from tensorflow.keras.layers import Input, Add, Dense, Activation, ZeroPadding2D, BatchNormalization, Flatten, Conv2D, MaxPooling2D, AveragePooling2D, Dropout
62
  from tensorflow.keras.models import Model
63
  from tensorflow.keras.initializers import GlorotUniform
 
89
  test_dir = "test"
90
 
91
  else:
92
+ # **CRITICAL: Explicitly define the paths RELATIVE to where you run the script**
93
+ # Get the directory where the script is located.
94
+ script_dir = os.path.dirname(os.path.abspath(__file__))
95
+
96
+ # Construct the full paths. This is the most reliable way to do it.
97
+ train_dir = os.path.join(script_dir, "train")
98
+ val_dir = os.path.join(script_dir, "val")
99
+ test_dir = os.path.join(script_dir, "test")
100
+
101
+ # ***VERY IMPORTANT DEBUGGING OUTPUT***
102
+ print(f"Script directory: {script_dir}")
103
+ print(f"Calculated train_dir: {train_dir}")
104
+ print(f"Calculated val_dir: {val_dir}")
105
+ print(f"Calculated test_dir: {test_dir}")
106
 
107
  if not os.path.exists(train_dir):
108
  print(f"Error: Training data directory not found at {train_dir}")
 
356
  except Exception as e:
357
  print(f"An error occurred during training: {e}")
358
  print("Please check your data and model configuration.")