newRoop commited on
Commit
d8be1c6
Β·
verified Β·
1 Parent(s): eea2cd1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -13
app.py CHANGED
@@ -1,6 +1,6 @@
1
  import subprocess
2
  import sys
3
- import os # Import the os module
4
 
5
  def install_tensorflow():
6
  """
@@ -8,13 +8,12 @@ def install_tensorflow():
8
  """
9
  try:
10
  print("Installing TensorFlow...")
11
- # Use subprocess.run for more robust command execution
12
  result = subprocess.run(
13
- [sys.executable, "-m", "pip", "install", "tensorflow"], # Install tensorflow
14
- check=True, # Raise an exception if the command fails
15
- stdout=subprocess.PIPE, # Capture standard output
16
- stderr=subprocess.PIPE, # Capture standard error
17
- text=True, # Return output as text
18
  )
19
  print("TensorFlow installed successfully.")
20
  print(result.stdout)
@@ -46,7 +45,6 @@ def check_tensorflow_installation():
46
  install_tensorflow()
47
  return False
48
 
49
- # Check and install TensorFlow if necessary
50
  if not check_tensorflow_installation():
51
  check_tensorflow_installation()
52
 
@@ -77,10 +75,26 @@ if IS_COLAB:
77
  val_dir = 'val'
78
  test_dir = 'test'
79
  else:
80
- # Define your data directories for local system
81
- train_dir = "data/train" # local paths
82
- val_dir = "data/val"
83
- test_dir = "data/test"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
 
85
  img_height, img_width = 224, 224
86
  batch_size = 32
@@ -256,7 +270,6 @@ def ResNetCustom(input_shape=(224, 224, 3), classes=2, num_blocks_per_stage=[2,
256
  return model
257
 
258
  # Build the model
259
- # You can customize the number of blocks per stage here. For a ResNet-10, use [1,1,1,1]
260
  model = ResNetCustom(input_shape=(img_height, img_width, 3), classes=num_classes, num_blocks_per_stage=[1, 1, 1, 1])
261
 
262
  # Compile the model
 
1
  import subprocess
2
  import sys
3
+ import os
4
 
5
  def install_tensorflow():
6
  """
 
8
  """
9
  try:
10
  print("Installing TensorFlow...")
 
11
  result = subprocess.run(
12
+ [sys.executable, "-m", "pip", "install", "tensorflow"],
13
+ check=True,
14
+ stdout=subprocess.PIPE,
15
+ stderr=subprocess.PIPE,
16
+ text=True,
17
  )
18
  print("TensorFlow installed successfully.")
19
  print(result.stdout)
 
45
  install_tensorflow()
46
  return False
47
 
 
48
  if not check_tensorflow_installation():
49
  check_tensorflow_installation()
50
 
 
75
  val_dir = 'val'
76
  test_dir = 'test'
77
  else:
78
+ # **IMPORTANT: Update these paths to the actual location of your data!**
79
+ train_dir = "/path/to/your/data/train" # Replace with your actual path
80
+ val_dir = "/path/to/your/data/val" # Replace with your actual path
81
+ test_dir = "/path/to/your/data/test" # Replace with your actual path
82
+
83
+ if not os.path.exists(train_dir):
84
+ print(f"Error: Training data directory not found at {train_dir}")
85
+ print("Please make sure the path is correct and the directory exists.")
86
+ sys.exit(1)
87
+ if not os.path.exists(val_dir):
88
+ print(f"Error: Validation data directory not found at {val_dir}")
89
+ print("Please make sure the path is correct and the directory exists.")
90
+ sys.exit(1)
91
+ if not os.path.exists(test_dir):
92
+ print(f"Error: Test data directory not found at {test_dir}")
93
+ print("Please make sure the path is correct and the directory exists.")
94
+ sys.exit(1)
95
+ print(f"Training data directory: {train_dir}")
96
+ print(f"Validation data directory: {val_dir}")
97
+ print(f"Test data directory: {test_dir}")
98
 
99
  img_height, img_width = 224, 224
100
  batch_size = 32
 
270
  return model
271
 
272
  # Build the model
 
273
  model = ResNetCustom(input_shape=(img_height, img_width, 3), classes=num_classes, num_blocks_per_stage=[1, 1, 1, 1])
274
 
275
  # Compile the model