gohar shah
gohar shah

Reputation: 175

Unable to store numpy.ndarray' object has no attribute 'save'

I have the following storing prediction data a larger NumPy array and sending it server. I tried Zlib compression but it's affecting the application performance.

def forward_data(frame,count):
   global m1, m2, model_split_arg
   source = cv2.imdecode(np.fromstring(base64.b64decode(frame), dtype=np.uint8), 1)
   image = img_to_array(source)
   image = image.reshape((1, image.shape[0], image.shape[1], image.shape[2]))
   preds = m1.predict(preprocess_input(image))
   preds.save()
   buf = io.BytesIO()  
   np.savez_compressed(buf, preds)

Error: preds.save() AttributeError: 'numpy.ndarray' object has no attribute 'save'

Upvotes: 3

Views: 3540

Answers (2)

bhola prasad
bhola prasad

Reputation: 725

# a numpy array

result.importances_mean
array([-1.43651529e-03, -2.73401297e-03,  9.26784059e-05, -7.41427247e-04,
        3.56811863e-03,  2.78035218e-03,  3.70713624e-03,  5.51436515e-03,
        1.16821131e-01,  9.26784059e-05,  9.26784059e-04, -1.80722892e-03,
       -1.71455051e-03, -1.29749768e-03, -9.26784059e-05, -1.43651529e-03,
        0.00000000e+00, -1.11214087e-03, -4.63392030e-05, -4.63392030e-04,
        1.20481928e-03,  5.42168675e-03, -5.56070436e-04,  8.34105653e-04,
       -1.85356812e-04,  0.00000000e+00, -9.73123262e-04, -1.43651529e-03,
       -1.76088971e-03])

# save the array format - np.save(filename.npy, array)

np.save(os.path.join(model_path, "permutation_imp.npy"), result.importances_mean)

# load the array format - np.load(filename.npy)

res = np.load(os.path.join(model_path, "permutation_imp.npy"))
res
array([-1.43651529e-03, -2.73401297e-03,  9.26784059e-05, -7.41427247e-04,
        3.56811863e-03,  2.78035218e-03,  3.70713624e-03,  5.51436515e-03,
        1.16821131e-01,  9.26784059e-05,  9.26784059e-04, -1.80722892e-03,
       -1.71455051e-03, -1.29749768e-03, -9.26784059e-05, -1.43651529e-03,
        0.00000000e+00, -1.11214087e-03, -4.63392030e-05, -4.63392030e-04,
        1.20481928e-03,  5.42168675e-03, -5.56070436e-04,  8.34105653e-04,
       -1.85356812e-04,  0.00000000e+00, -9.73123262e-04, -1.43651529e-03,
       -1.76088971e-03])

Upvotes: 0

Shag
Shag

Reputation: 430

Try using

cv2.imwrite(path,img_to_save)

to save

Upvotes: 2

Related Questions