from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten, Dense model = Sequential([ Conv2D(32, (3,3), activation='relu', input_shape=(32, 32, 3)), MaxPooling2D((2,2)), Conv2D(64, (3,3), activation='relu'), MaxPooling2D((2,2)), Flatten(), Dense(128, activation='relu'), Dense(10, activation='softmax') ]) # load trained model model.load_weights('my_model_weights.h5') # predict classes of new images predictions = model.predict(new_images)
from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Embedding, Flatten, Dense model = Sequential([ Embedding(input_dim=1000, output_dim=64, input_length=100), Flatten(), Dense(64, activation='relu'), Dense(1, activation='sigmoid') ]) # load trained model model.load_weights('my_model_weights.h5') # predict sentiment of new text predictions = model.predict(new_text)In both examples, we first define our model architecture using the Sequential module, then load the trained weights using the load_weights method, and finally use the predict method to make predictions on new data.