Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import tensorflow as tf
|
|
|
|
|
|
|
| 2 |
import os
|
| 3 |
-
# Avoid OOM errors by setting GPU Memory Consumption Growth
|
| 4 |
-
gpus = tf.config.experimental.list_physical_devices('GPU')
|
| 5 |
-
for gpu in gpus:
|
| 6 |
-
tf.config.experimental.set_memory_growth(gpu, True)
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
|
| 3 |
+
|
| 4 |
import tensorflow as tf
|
| 5 |
+
import cv2
|
| 6 |
+
import imghdr
|
| 7 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
# Clean image files
|
| 10 |
+
data_dir = 'data'
|
| 11 |
+
image_exts = ['jpeg', 'jpg', 'bmp', 'png']
|
| 12 |
+
|
| 13 |
+
for image_class in os.listdir(data_dir):
|
| 14 |
+
for image in os.listdir(os.path.join(data_dir, image_class)):
|
| 15 |
+
image_path = os.path.join(data_dir, image_class, image)
|
| 16 |
+
try:
|
| 17 |
+
img = cv2.imread(image_path)
|
| 18 |
+
tip = imghdr.what(image_path)
|
| 19 |
+
if tip not in image_exts:
|
| 20 |
+
print('Removing:', image_path)
|
| 21 |
+
os.remove(image_path)
|
| 22 |
+
except Exception as e:
|
| 23 |
+
print('Issue with image:', image_path)
|