finally, I reached to this code
class FeatureExtractor(nn.Module):
      def __init__(self, model):
            super(FeatureExtractor, self).__init__()

            self.classifier= list(model.classifier)
            self.classifier = nn.Sequential(*self.classifier)
            self.flatten = nn.Flatten()
# Extract the last part of fully-connected layer from Alexnet
            self.fc = model.classifier[6]
  
      def forward(self, x):
# It will take the input 'x' until it returns the feature vector called 'out'
         out = self.classifier(x)
         out = self.flatten(out)
         out = self.fc(out) 
         return out 

# Initialize the model for one  class
model.classifier[6] = nn.Linear(model.classifier[6].in_features, 1)
new_model = FeatureExtractor(model)

# Change the device to GPU
device = torch.device('cuda:0' if torch.cuda.is_available() else "cpu")
new_model = new_model.to(device)


from tqdm import tqdm
import numpy as np

# Transform the image, so it becomes readable with the model
transform = transforms.Compose([
  transforms.ToPILImage(),
  transforms.Resize(224),
  transforms.ToTensor()                              
])

# Will contain the feature
features = []
DATADIR = ('E:/........................')
path = os.path.join(DATADIR)  

# Iterate each image
for i in os.listdir(path):
    
  # Read the file
        img = cv2.imread(os.path.join(path,i)) 
        # Transform the image
        img = transform(img)
        img = img.reshape(1, 3, 224, 224)
        img = img.to(device)
        # We only extract features, so we don't need gradient
        with torch.no_grad():
        # Extract the feature from the image
               feature = model(img)
    # Convert to NumPy Array, Reshape it, and save it to features variable
        features.append(feature.cpu().detach().numpy().reshape(-1))

# Convert to NumPy Array
features = np.array(features)
features.shape

the output of the last line was     (826, 1) !!! why …my target is (826,4069) ==(number of samples, featuers in the last fc layer)
can anyone help me?