Download model.py from hitty/Vegetable: direct link, hf CLI and curl.
- Browser
- Download file 1.33 kB
-
https://huggingface.co/spaces/hitty/Vegetable/resolve/fca43681d94de28ee4e306d6a1e194022e44e33e/model.py
- Command line
-
hf download hf://spaces/hitty/Vegetable@fca43681d94de28ee4e306d6a1e194022e44e33e/model.py
-
curl -L -o model.py https://huggingface.co/spaces/hitty/Vegetable/resolve/fca43681d94de28ee4e306d6a1e194022e44e33e/model.py
1.33 kB
| import tensorflow as tf | |
| from tensorflow.keras.layers import Dropout, Dense,GlobalAveragePooling2D, Input | |
| from tensorflow.keras.applications import EfficientNetB7 | |
| from tensorflow.keras.models import Model | |
| def create_effnetb2_model(num_classes=15, seed=42): | |
| """Creates an EfficientNetB7 model with additional layers for fine-tuning. | |
| Args: | |
| num_classes (int, optional): Number of classes in the classifier head. | |
| Defaults to 3. | |
| seed (int, optional): Random seed value. Defaults to 42. | |
| Returns: | |
| model (tensorflow.keras.Model): EffNetB7 model with additional layers. | |
| """ | |
| # Load the pretrained EffNetB7 model | |
| base_model = EfficientNetB7(include_top=False, weights='imagenet', input_shape=(224, 224, 3)) | |
| # Freeze all layers in the base model except the last few | |
| for layer in base_model.layers[:-10]: | |
| layer.trainable = False | |
| # Add additional layers | |
| x = base_model.output | |
| x = GlobalAveragePooling2D()(x) | |
| x = Dropout(0.3)(x) | |
| x = Dense(256, activation='relu')(x) | |
| x = Dropout(0.3)(x) | |
| x = Dense(128, activation='relu')(x) | |
| # Add a dense layer for classification | |
| outputs = Dense(num_classes, activation='softmax')(x) | |
| # Create the final model | |
| model = Model(inputs=base_model.input, outputs=outputs) | |
| return model | |