开发者

I keep getting permission denied?

import os
import tensorflow as tf

# Get the current working directory
path = os.getcwd()

# Define the path components
filename = 'Downloads'
filename2 = 'crops'
filename3 = 'train'
filename4 = 'banana'

# Join the path components using the correct path separator
file_path = os.path.join(path, filename, filename2, filename3, filename4)

# Check if the file or directory exists
if os.path.exists(file_path):
    # If it exists, grant read and write permissions to the owner of the directory
    os.system('icacls ' + file_path + ' /grant "Alex":(OI)(CI)(RX,W)')
    print('success')
else:
    # If the file or directory does not exist, print an error message
    print("fail")

# Load the data
(X_train, y_train), (X_test, y_test) = tf.keras.datasets.mnist.load_data(file_path)

# Reshape the data to have a single channel
X_train = X_train.reshape((X_train.shape[0], 28, 28, 1))
X_test = X_test.reshape((X_test.shape[0], 28, 28, 1))

# Convert the data to floating point values and normalize them
X_train = X_train.astype(np.float32) / 255.0
X_test = X_test.astype(np.float32) / 255.0

# Create a CNN model
model = tf.keras.models.Sequential()
model.开发者_如何学Goadd(tf.keras.layers.Conv2D(32, (3, 3), activation='relu', input_shape=(28, 28, 1)))
model.add(tf.keras.layers.MaxPooling2D((2, 2)))
model.add(tf.keras.layers.Conv2D(64, (3, 3), activation='relu'))
model.add(tf.keras.layers.MaxPooling2D((2, 2)))
model.add(tf.keras.layers.Conv2D(64, (3, 3), activation='relu'))
model.add(tf.keras.layers.Flatten())
model.add(tf.keras.layers.Dense(64, activation='relu'))
model.add(tf.keras.layers.Dense(10, activation='softmax'))

# Compile the model
model.compile(optimizer='adam',
              loss='sparse_categorical_crossentropy',
              metrics=['accuracy'])

# Train the model
model.fit(X_train, y_train, epochs=5)

# Save the trained model
model.save('food_recognition')

I cut off all the code below the following:

if os.path.exists(file_path):
    # If it exists, grant read and write permissions to the owner of the directory
    os.system('icacls ' + file_path + ' /grant "Alex":(OI)(CI)(RX,W)')
    print('success')
else: 
    print("fail")

to check and it returns success, so I know the path exists but it fails when I actually try and read from the directory, so I guess that means my method of granting permissions is not working? Also when I check the path of file_path it returns

C:\\Users\\Alex\\Downloads\\crops\\train\\banana

but in my file browser there are no \ only \ so could that have something to do with it?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜