Spaces:
Sleeping
Sleeping
Update pages/15_TransferLearning_HF.py
Browse files
pages/15_TransferLearning_HF.py
CHANGED
@@ -3,7 +3,6 @@ import tensorflow as tf
|
|
3 |
from transformers import ViTFeatureExtractor, TFAutoModelForImageClassification
|
4 |
import tensorflow_datasets as tfds
|
5 |
import matplotlib.pyplot as plt
|
6 |
-
import numpy as np
|
7 |
|
8 |
# Load the dataset
|
9 |
dataset_name = "cats_vs_dogs"
|
@@ -35,8 +34,9 @@ base_model.trainable = False
|
|
35 |
|
36 |
# Add custom layers on top
|
37 |
inputs = tf.keras.Input(shape=(224, 224, 3))
|
38 |
-
|
39 |
-
|
|
|
40 |
x = tf.keras.layers.Dense(256, activation='relu')(x)
|
41 |
x = tf.keras.layers.Dropout(0.5)(x)
|
42 |
outputs = tf.keras.layers.Dense(1, activation='sigmoid')(x)
|
|
|
3 |
from transformers import ViTFeatureExtractor, TFAutoModelForImageClassification
|
4 |
import tensorflow_datasets as tfds
|
5 |
import matplotlib.pyplot as plt
|
|
|
6 |
|
7 |
# Load the dataset
|
8 |
dataset_name = "cats_vs_dogs"
|
|
|
34 |
|
35 |
# Add custom layers on top
|
36 |
inputs = tf.keras.Input(shape=(224, 224, 3))
|
37 |
+
features = feature_extractor(inputs, return_tensors="tf")["pixel_values"]
|
38 |
+
base_output = base_model(features)[0] # Extract base model output
|
39 |
+
x = tf.keras.layers.Flatten()(base_output)
|
40 |
x = tf.keras.layers.Dense(256, activation='relu')(x)
|
41 |
x = tf.keras.layers.Dropout(0.5)(x)
|
42 |
outputs = tf.keras.layers.Dense(1, activation='sigmoid')(x)
|