W
W
wndr wndr2021-06-19 08:50:47
Python
wndr wndr, 2021-06-19 08:50:47

" No module named 'sklearn.preprocessing.label' " how to fix this error?

def prescript(file): 
        ap = argparse.ArgumentParser()
        ap.add_argument("-i", "--image",type=str, default=file,help="path to input image we are going to classify")
        ap.add_argument("-m", "--model",type=str,default="smallvggnet.model",help="path to trained Keras model")
        ap.add_argument("-l", "--label-bin",type=str,default="smallvggnet_lb.pickle",help="path to label binarizer")
        ap.add_argument("-w", "--width", type=int, default=64, help="target spatial dimension width")
        ap.add_argument("-e", "--height", type=int, default=64, help="target spatial dimension height")
        ap.add_argument("-f", "--flatten", type=int, default=-1, help="whether or not we should flatten the image")
        args = vars(ap.parse_args())
        
        image = cv2.imread(file)
        output = image.copy()
        image = cv2.resize(image, (args["width"], args["height"]))
        image = image.astype("float") / 255.0        
        if args["flatten"] > 0:
                image = image.flatten()
                image = image.reshape((1, image.shape[0]))
        else:
                image = image.reshape((1, image.shape[0], image.shape[1], image.shape[2]))
        
        model = load_model(args["model"])
        lb = pickle.loads(open(args["label_bin"], "rb").read())        
        preds = model.predict(image)
        i = preds.argmax(axis=1)[0]
        label = lb.classes_[i]        
        text = "{}: {:.2f}%".format(label, preds[0][i] * 100)
        print(text[0]) 
        global result
        result = text[0]


lb = pickle.loads(open(args["label_bin"], "rb").read())
ModuleNotFoundError: No module named 'sklearn.preprocessing.label'


requirements.txt

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
Jalal Nasirov, 2021-06-19
@Best_Loops

Try updating (if there are updates), preferably all, modules.
In some modules, when updating, they rename variables.

W
wndr wndr, 2021-06-21
@wunderer1337

I just rewrote two lines without changing them in any way and everything worked, miracle

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question