Categories
Misc

Can someone help me write this code so its suitable for Tensorflow 2.x ?

Been getting the Name Error Session

CODE :

”’

from django.shortcuts import render

from django.core.files.storage import FileSystemStorage

import tensorflow as tf

from tensorflow import keras

gpuoptions = tf.compat.v1.GPUOptions(allow_growth=True)

session = tf.compat.v1.Session(config=tf.compat.v1.ConfigProto(gpu_options=gpuoptions))

models = keras.models.Sequential

classifier = Sequential()

from tensorflow import keras

import keras.backend as K

K.set_session(session)

from tensorflow import Session

import os

from keras.models import Sequential

from tensorflow.keras.models import load_model

# #from keras.preprocessing import image

from tensorflow.keras.preprocessing import image

import json

from tensorflow import Graph, Session

def index(request):

context={‘a’:1}

return render(request,’index.html’,context)

def predictImage(request):

img_height, img_width=224,224

print (request)

print (request.POST.dict())

fileObj=request.FILES[‘filePath’]

dir_path=’seamines_images’

fs=FileSystemStorage()

filePathName=fs.save(fileObj.name,fileObj)

filePathName=fs.url(filePathName)

if fileObj.name in os.listdir(dir_path) :

fileObj.name=’seamine’

context={‘filePathName’:filePathName,’predictedLabel’:fileObj.name}

else:

fileObj.name=’Not a seamine’

context={‘filePathName’:filePathName,’predictedLabel’:fileObj.name}

return render(request,’index.html’,context)

def viewDataBase(request):

import os

listOfImages=os.listdir(‘media’)

listOfImagesPath=[‘media/’+i for i in listOfImages]

context={‘listOfImagesPath’:listOfImagesPath}

return render(request,’viewDB.html’,context)

”’

submitted by /u/nerdysukzz700
[visit reddit] [comments]

Leave a Reply

Your email address will not be published. Required fields are marked *