This study addressed the autonomous planning of three-dimensional (3D) underwater inspection paths for autonomous underwater vehicles (AUVs) in marine ranching by integrating differential evolution and particle swarm optimization (PSO) algorithms. First, a modified PSO algorithm incorporating swap operators, mutation, and crossover strategies was employed to enable autonomous obstacle avoidance during the inspection of offshore net cages in fish farms situated within a 3D marine environment. This approach addresses the problem of planning full-traversal paths for multiple inspection points. Second, the performance of the proposed algorithm was assessed through comparative tests with other algorithms. The proposed algorithm demonstrated significant improvements in convergence speed, accuracy, and stability under complex scenarios involving multiple optima and intense oscillations. To validate the superiority and overall planning proficiency of the modified method, an experimental setup comprising of two distinct 3D marine cage environments with a series of checkpoints was utilized. The experimental results demonstrated the ability of the proposed algorithm to generate an optimal path while traversing all inspection points of fish farm offshore net cages. By ensuring the safety of AUVs and closely adhering to the surfaces of offshore net cages during the inspection process, the algorithm exhibits remarkable adaptability to specific application scenarios, effectively mitigating concerns related to local optima and premature convergence.