eaglelandsonce commited on
Commit
617a51d
·
verified ·
1 Parent(s): fbd0bc7

Update pages/15_TransferLearning_HF.py

Browse files
Files changed (1) hide show
  1. pages/15_TransferLearning_HF.py +3 -3
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
- x = feature_extractor(inputs)
39
- x = tf.keras.layers.Flatten()(base_model(x)[0])
 
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)