fischjos commited on
Commit
27ecaa2
1 Parent(s): 52b277f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -9
app.py CHANGED
@@ -1,6 +1,6 @@
1
  import os
 
2
  import numpy as np
3
- import gradio as gr
4
  import matplotlib.pyplot as plt
5
  import tensorflow as tf
6
  from tensorflow.keras.preprocessing.image import ImageDataGenerator
@@ -9,10 +9,15 @@ from tensorflow.keras.layers import Dense, GlobalAveragePooling2D, Dropout, Batc
9
  from tensorflow.keras.models import Model
10
  from tensorflow.keras.optimizers import Adam
11
 
12
- # Suppress TensorFlow logging and warnings
13
- os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' # Suppress TensorFlow logging (1 = INFO, 2 = WARNING, 3 = ERROR)
14
- tf.get_logger().setLevel('ERROR')
15
- tf.autograph.set_verbosity(2)
 
 
 
 
 
16
 
17
  # Function to find the greatest batch size that fully divides the total samples
18
  def find_batch_size(total_samples, initial_batch_size):
@@ -21,10 +26,14 @@ def find_batch_size(total_samples, initial_batch_size):
21
  return bs
22
  return 1 # Fallback to 1 if no perfect divisor is found
23
 
24
- # Path to the image data directory
25
- base_dir = 'pokemon-images-first-generation17000-files/pokemon' # Adjust path as needed
26
- if not os.path.exists(base_dir):
27
- raise Exception("The specified base path does not exist. Please verify the path.")
 
 
 
 
28
 
29
  # Define the Pokémon classes to be classified
30
  classes = ['Doduo', 'Geodude', 'Zubat']
 
1
  import os
2
+ import zipfile
3
  import numpy as np
 
4
  import matplotlib.pyplot as plt
5
  import tensorflow as tf
6
  from tensorflow.keras.preprocessing.image import ImageDataGenerator
 
9
  from tensorflow.keras.models import Model
10
  from tensorflow.keras.optimizers import Adam
11
 
12
+ # Function to download and extract the dataset
13
+ def download_and_extract_dataset(dataset_name):
14
+ # Make sure the kaggle.json file is in the proper location
15
+ os.environ['KAGGLE_CONFIG_DIR'] = os.path.expanduser("~/.kaggle/")
16
+ # Download the dataset
17
+ os.system(f'kaggle datasets download -d mikoajkolman/pokemon-images-first-generation17000-files')
18
+ # Extract the dataset
19
+ with zipfile.ZipFile(f'{dataset_name}.zip', 'r') as zip_ref:
20
+ zip_ref.extractall('.')
21
 
22
  # Function to find the greatest batch size that fully divides the total samples
23
  def find_batch_size(total_samples, initial_batch_size):
 
26
  return bs
27
  return 1 # Fallback to 1 if no perfect divisor is found
28
 
29
+ # Suppress TensorFlow logging and warnings
30
+ os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' # Suppress TensorFlow logging (1 = INFO, 2 = WARNING)
31
+ tf.get_logger().setLevel('ERROR')
32
+ tf.autograph.set_verbosity(2)
33
+
34
+ # Download and extract the dataset
35
+ dataset_name = 'mikoajkolman/pokemon-images-first
36
+
37
 
38
  # Define the Pokémon classes to be classified
39
  classes = ['Doduo', 'Geodude', 'Zubat']