rewrite python keras resnet50 classifier script in pytorch

Job ID: 33837231

Budget: $30 – $250 USD

I have a simple python/keras/resnet50 script to train an image classification model. The resnet50 part is like 40 lines of code. I need someone to port it to pytorch. Below is the heart of the script that needs to change. If you know pytorch, this should be easy to do. This is not the whole script, but if you can show me reason to believe you can do this, I will share the script with you.

A successfully completed project will run an entire script with the resnet50 model. The script as it exists with keras does this:
load the training and validation data and labels
build and compile model
train (fit) model
build accuracy matrix


input_layer=layers.Input(shape=(nrows,ncolumns,channels))

resnet_model=resnet50.ResNet50(weights='imagenet',input_tensor=input_layer,include_top=False)

last_layer=resnet_model.output # we are taking last layer of the model

# Add flatten layer: we are extending Neural Network by adding flattn layer
flatten=layers.Flatten()(last_layer)

# Add dense layer to the final output layer
output_layer=layers.Dense(len(CATEGORIES),activation='softmax')(flatten)

# Creating model with input and output layer
model=models.Model(inputs=input_layer,outputs=output_layer)

# we are making all the layers intrainable except the last layer
for layer in model.layers[:-1]:
layer.trainable=False

xtrain, xtest, ytrain, ytest = train_test_split(x,y,test_size=0.2,random_state=5)

model.compile(loss='categorical_crossentropy', optimizer='adam',metrics=['accuracy'])

# 13 Fit the Model
print("fitting the model")

history = model.fit(xtrain,ytrain,epochs=numEpochs,batch_size=64,verbose=True,validation_data=(xtest,ytest))
Related categories: Python Machine Learning (ML) Tensorflow Keras Pytorch