File ~\anaconda3\lib\site-packages\numpy\lib\_datasource.py:533 in open raise IOError("%s not found." % path)

Viewed 12

I have this code:

import numpy as np


#from bp.deep_bp import deep_train
def deep_train(train_x, train_y, test_x, test_y, layers_dims):
    parameters = L_layer_model(train_x, train_y, layers_dims, num_iterations=2500, print_cost=True)
    pred_train = predict(train_x, train_y, parameters)
    pred_test = predict(test_x, test_x, parameters)
    
#from bp.shallow_bp import shallow_train
def shallow_train(train_set_x, train_set_y, test_set_x, test_set_y, sys_layers_dims):
     dataset = load_resize_dataset()
     train_set_x = dataset['train_set_x']
     train_set_y = dataset['train_set_y']
     test_set_x = dataset['test_set_x']
     test_set_y = dataset['test_set_y']
     d = model(train_set_x, train_set_y, test_set_x, test_set_y, num_iterations=2000, learning_rate=0.0001,
        print_cost=True)
    
    
#from factory.bp_data_factory import load_cat_dataset
def load_cat_dataset():
            train_dataset = h5py.File('D:\research\SoftWareReliability-master\SoftWareReliability-master\resource\train_catvnoncat.h5', "r")
            train_set_x_orig = np.array(train_dataset["train_set_x"][:])  # train set features
            train_set_y_orig = np.array(train_dataset["train_set_y"][:])  # train set labels
    
            test_dataset = h5py.File('D:\research\SoftWareReliability-master\SoftWareReliability-master\resource\test_catvnoncat.h5', "r")
            test_set_x_orig = np.array(test_dataset["test_set_x"][:])  # test set features
            test_set_y_orig = np.array(test_dataset["test_set_y"][:])  # test set labels
    
            classes = np.array(test_dataset["list_classes"][:])  # the list of classes
    
            train_set_y_orig = train_set_y_orig.reshape((1, train_set_y_orig.shape[0]))
            test_set_y_orig = test_set_y_orig.reshape((1, test_set_y_orig.shape[0]))
    
            return train_set_x_orig, train_set_y_orig, test_set_x_orig, test_set_y_orig, classes
        
#from factory.graph_data_factory import load_sys_dataset     
def load_sys_dataset():
    path = 'D:\research\SoftWareReliability-master\SoftWareReliability-master\resource\sourceData.txt'
    data = np.loadtxt(path)
    
    n = data.shape[0]
    
    data2 = np.zeros(shape=n + 1)
    data2[0] = 0
    for i in range(n):
        data2[i + 1] = data[i][1]
    
    return data2
    
    
def shallow_bp(train_x, train_y, test_x, test_y, sys_layers_dims):
    shallow_train(train_x, train_y, test_x, test_y, sys_layers_dims)


#def deep_dp(train_x, train_y, test_x, test_y, layers_dims):
 #   deep_train(train_x, train_y, test_x, test_y, layers_dims)


def read_decode_cat_data():
    train_x_orig, train_y, test_x_orig, test_y, classes = load_cat_dataset()

    m_train = train_x_orig.shape[0]
    num_px = train_x_orig.shape[1]
    m_test = test_x_orig.shape[0]

    print("Number of training examples: " + str(m_train))
    print("Number of testing examples: " + str(m_test))
    print("Each image is of size: (" + str(num_px) + ", " + str(num_px) + ", 3)")
    print("train_x_orig shape: " + str(train_x_orig.shape))
    print("train_y shape: " + str(train_y.shape))
    print("test_x_orig shape: " + str(test_x_orig.shape))
    print("test_y shape: " + str(test_y.shape))

    train_x_flatten = train_x_orig.reshape(train_x_orig.shape[0],
                                           -1).T
    test_x_flatten = test_x_orig.reshape(test_x_orig.shape[0], -1).T

    train_x = train_x_flatten / 255.
    test_x = test_x_flatten / 255.

    print("train_x's shape: " + str(train_x.shape))
    print("test_x's shape: " + str(test_x.shape))

    n_x = 12288  # num_px * num_px * 3
    n_h = 7
    n_y = 1
    layers_dims = (n_x, n_h, n_y)
    return train_x, train_y, test_x, test_y


def Normalize(data):
    m = np.mean(data)
    mx = max(data)
    mn = min(data)
    print('mean: ' + str(m) + ' mx:' + str(mx) + ' mn:' + str(mn))
    return [(float(i) - m) / (mx - mn) for i in data]


def read_decode_sys_data():
    y = load_sys_dataset()
    sum_count = len(y)
    y = np.array(y)
    np.delete(y, [y[0]])
    x = np.arange(start=0, stop=sum_count, step=1)

    x = Normalize(x)
    y = Normalize(y)
    x=np.array(x)
    y=np.array(y)

    last_train_index = int((sum_count - 1) * 0.8)
    train_x = x[1:last_train_index]
    train_y = y[1:last_train_index]
    test_x = x[last_train_index:]
    test_y = y[last_train_index:]
    train_x_flatten = train_x.reshape(train_x.shape[0],
                                      -1).T
    test_x_flatten = test_x.reshape(test_y.shape[0], -1).T
    train_y = train_y.reshape(1, -1)
    test_y = test_y.reshape(1, -1)
    return train_x_flatten, train_y, test_x_flatten, test_y


if __name__ == '__main__':
    cat_layers_dims = [12288, 20, 7, 5, 1]
    sys_layers_dims = [1, 1]
    train_x, train_y, test_x, test_y = read_decode_sys_data()
    shallow_bp(train_x, train_y, test_x, test_y, sys_layers_dims)

it shows me this error:

Python 3.9.12 (main, Apr  4 2022, 05:22:27) [MSC v.1916 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.

IPython 8.2.0 -- An enhanced Interactive Python.

runfile('D:/research/SoftWareReliability-master/SoftWareReliability-master/presenter/bp_presenter.py', wdir='D:/research/SoftWareReliability-master/SoftWareReliability-master/presenter')
Traceback (most recent call last):

  File D:\research\SoftWareReliability-master\SoftWareReliability-master\presenter\bp_presenter.py:133 in <module>
    train_x, train_y, test_x, test_y = read_decode_sys_data()

  File D:\research\SoftWareReliability-master\SoftWareReliability-master\presenter\bp_presenter.py:106 in read_decode_sys_data
    y = load_sys_dataset()

  File D:\research\SoftWareReliability-master\SoftWareReliability-master\presenter\bp_presenter.py:45 in load_sys_dataset
    data = np.loadtxt(path)

  File ~\anaconda3\lib\site-packages\numpy\lib\npyio.py:1067 in loadtxt
    fh = np.lib._datasource.open(fname, 'rt', encoding=encoding)

  File ~\anaconda3\lib\site-packages\numpy\lib\_datasource.py:193 in open
    return ds.open(path, mode, encoding=encoding, newline=newline)

  File ~\anaconda3\lib\site-packages\numpy\lib\_datasource.py:533 in open
    raise IOError("%s not found." % path)

esource\sourceData.txt not found.r\SoftWareReliability-master

its looks in this part:

#from factory.graph_data_factory import load_sys_dataset     
def load_sys_dataset():
    path = 'D:\research\SoftWareReliability-master\SoftWareReliability-master\resource\sourceData.txt'
    data = np.loadtxt(path)
    
    n = data.shape[0]
    
    data2 = np.zeros(shape=n + 1)
    data2[0] = 0
    for i in range(n):
        data2[i + 1] = data[i][1]
    
    return data2
    

but this path is 100% correct, whats the problem?

'D:\research\SoftWareReliability-master\SoftWareReliability-master\resource\sourceData.txt'
0 Answers
Related