import tensorflow as tf
import cv2
import numpy as np
img_address = 'C:\\Users\\Administrator\\Desktop\\faster-rcnn-keras-master\\img\\street.jpg'
def VGG(inputs):
x = inputs
# Conv1
x = tf.keras.layers.Conv2D(filters=64, kernel_size=(3,3), padding='Same', activation=tf.nn.relu)(x)
x = tf.keras.layers.Conv2D(filters=64, kernel_size=(3,3), padding='Same', activation=tf.nn.relu)(x)
x - tf.keras.layers.MaxPooling2D(pool_size=(2,2), strides=2)(x)
# Conv2
x = tf.keras.layers.Conv2D(filters=128, kernel_size=(3,3), padding='Same', activation=tf.nn.relu)(x)
x = tf.keras.layers.Conv2D(filters=128, kernel_size=(3,3), padding='Same', activation=tf.nn.relu)(x)
x = tf.keras.layers.MaxPooling2D(pool_size=(2,2), strides=2)(x)
# Conv3
x = tf.keras.layers.Conv2D(256, (3, 3), padding='Same', activation=tf.nn.relu)(x)
x = tf.keras.layers.Conv2D(256, (3, 3), padding='Same', activation=tf.nn.relu)(x)
x = tf.keras.layers.Conv2D(256, (3, 3), padding='Same', activation=tf.nn.relu)(x)
x = tf.keras.layers.MaxPooling2D(pool_size=(2, 2), strides=2)(x)
# Conv4
x = tf.keras.layers.Conv2D(512, (3, 3), padding='Same', activation=tf.nn.relu)(x)
x = tf.keras.layers.Conv2D(512, (3, 3), padding='Same', activation=tf.nn.relu)(x)
x = tf.keras.layers.Conv2D(512, (3, 3), padding='Same', activation=tf.nn.relu)(x)
x = tf.keras.layers.MaxPooling2D(pool_size=(2, 2), strides=2)(x)
# Conv5
x = tf.keras.layers.Conv2D(512, (3, 3), padding='Same', activation=tf.nn.relu)(x)
x = tf.keras.layers.Conv2D(512, (3, 3), padding='Same', activation=tf.nn.relu)(x)
x = tf.keras.layers.Conv2D(512, (3, 3), padding='Same', activation=tf.nn.relu)(x)
x = tf.keras.layers.MaxPooling2D(pool_size=(2, 2), strides=2)(x)
return x
def img_solve():
img = cv2.imread(img_address)
img_shape = img.shape[0:2]
img_shape_short = np.min(img_shape)
ratio_img = 600. / img_shape_short
img_collected = cv2.resize(img, (int(img_shape[0] * ratio_img), int(img_shape[1] * ratio_img)))
img_collected = np.expand_dims(img_collected.astype(np.float32) / 255.0, axis=-1)
return img_collected
img = img_solve()
a= VGG(img)
print(img.shape)